当前位置:网站首页>Difference between redis hash and string
Difference between redis hash and string
2022-07-26 21:20:00 【The clouds are idle】
Similarities and differences
Suppose we want to save the computer information of a school redis
- Use string method :KEY Prefix computer information + School name + Device identifier ,value For specific information json
- Use hash Methods :KEY Prefix computer information + School name , In hash key Subdivision Device identifier
The same thing :
First, they have many commands with similar effects , such as set and hset,mset and hmset wait
In most cases, scenarios that use string storage use hash It can also be realized .
Difference
Their storage structure determines that they have some essential differences
Use hash The advantages of hashing
- Use hash Data can be placed in the same place for easy management , Instead of having to put the data in the whole database with a string , And it can also avoid misoperation .
- Use hash Hashing can not only reduce the number of keys created, but also avoid key name conflicts .
- Use hash Hashing saves more memory than using string keys . Because create in the database key All have database attached management information ( For example, the type of key , Last visit time, etc ), therefore keys The more , The more memory the server consumes in storing additional management information , At the same time, it is spent in the management database key Of cu’p The more you will be . and redis Ability will be right hash Do some low-level optimization for your storage , Less memory consumption .
Use strings in specific cases
- Use expiration function
because redis The expiration function of can only operate on the key, not the hash key field To operate .
Commands for binary storage - because redis At present, only string keys are supported setbit,getbit,bitop And other binary related command operations .
So use strings and hash If it's ok , Use as much as possible hash
————————————————
Copyright notice : This paper is about CSDN Blogger 「 Take off on the yard 」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/Frankltf/article/details/82976644
Big key problem
hash Many middle elements will cause big key.
But it seems that reading a single does not affect .
because redis Single thread , But if getall Or when it's deleted It will cause obstruction !
边栏推荐
- 立即报名:7 月 29 日推荐系统峰会 2022
- 【HCIA安全】双向NAT
- [HCIA security] user authentication
- Web3.0 时代,基于P2PDB实现一款Dapp的技术理论
- Relevant contents about wireless communication
- 详细图解b树及C语言实现
- What kind of security problems will the server encounter?
- Redis面试题
- The hardest lesson we learned from the crypto Market
- Leetcode hash table class
猜你喜欢

详解西部数据SMR叠瓦式硬盘的190二级编译器(译码表)模块

Why didn't Tencent create a game like "original God"

What is the function of the serializable interface?

2022开放原子全球开源峰会议程速递 | 7 月 27 日分论坛议程一览

2022 open atom global open source summit agenda express | list of sub forum agenda on July 27

没有网络怎么配置传奇SF登陆器自动读取列表

关于:获取当前客户端登录的域控
![[question] browser get request with token](/img/95/f0b7186f930c014495414c3fcdaa6e.png)
[question] browser get request with token
![[ffmpeg] add timestamp summary to video files](/img/ae/f3f24d16f5d30c276762163867546d.png)
[ffmpeg] add timestamp summary to video files

How to enter the specified user method body when debugging in idea?
随机推荐
Beginner experience of safety testing
我们从Crypto市场中学到的最艰难一课
Redis hash和string的区别
SPI configuration
Soft test --- database (1) database foundation
[pytorch advanced] preservation and use of pytorch model
手机\固定电话座机呼叫转移设置方法
[virtual machine data recovery] data recovery of XenServer virtual machine unavailable due to unexpected power failure
Leetcode array class
Basic use of livedatade
What kind of security problems will the server encounter?
【HCIA安全】用户认证
SprinBoot面试题
[hero planet July training leetcode problem solving daily] 26th and check the collection
【Oracle实训】-部署号称零停机迁移的OGG
QT基础第一天 (1)QT,GUI(图形用户接口)开发
IT系统为什么需要可观测性?
SSM整合实例
How to create a static object variable of its own class?
服务器的防护会遇到什么样的安全问题呢?