当前位置:网站首页>Interviewer: what is the internal implementation of hash data type in redis?
Interviewer: what is the internal implementation of hash data type in redis?
2022-07-04 13:52:00 【51CTO】
interviewer :Redis What are the basic data types in ?
I :Redis The basic data types of are : character string (string)、 Hash (hash)、 list (list)、 aggregate (set)、 Ordered set (zset).
interviewer : What is the internal implementation of hash data type ?
I was also immersed in the complacency of the last question , Suddenly, his expression solidified , The palms began to sweat .“ This .. Not much in-depth understanding ”, I hesitated .
interviewer : Go back and wait for the news .
This sentence is clear , And then there's no then . Failure is the mother of success , I'm not discouraged , Decided to mend it right away .
Encoding of hash
There are two kinds of hash encoding , Compressed list (ziplist) Hash table (hashtable). When the length of keys and values of all key value pairs is less than hash-max-ziplist-value
( The default is 64 byte ), And the number of key value pairs is less than hash-max-ziplist-entries
( The default is 512 individual ) When , The hash will be encoded using a compressed list , Otherwise, use hash table as encoding .
Let's give you an example :
here , The length of keys and values of all key value pairs and the number of key value pairs are relatively small , Hashes are encoded using a compressed list . Let's add a key value pair with a large value :
here , The encoding of hash is transformed from compressed list to encoding .
Of course , I haven't fully understood the above details yet “ conquer ” interviewer , We need to go deeper :)
The underlying implementation of hash
When the compressed list is used as the encoding of hash , A new key value pair is added to the hash data type , First, add the compressed list node of the key to the end of the compressed list , Then add the compressed list node of the value to the end of the compressed list .
therefore , In the compressed list of hash data types , The key value pair added first is in the head direction of the compressed list , The added key value pair is at the end of the compressed list ; The two nodes of the same key value pair are close together , The node of the key is first , The node of the value is after .
The compressed list uses a more compact memory structure to realize the continuous storage of multiple key value pairs , Better than hash table in saving memory .
When the hash table is used as the encoding of hash , Each key value pair is saved with a dictionary key value pair , Each key in the dictionary is a string object , Object to save key value pairs ; Each value of the dictionary is also a string object , Object to save the value of the key value pair .
Although hash tables do not compress lists, they save memory , But its reading and writing time complexity is O(1), Better time efficiency than compressed lists .
summary
The internal implementation of hash data type has compressed list (ziplist) Hash table (hashtable) Two kinds of . When the length of keys and values of hash data type is small and the number of key value pairs is small , Use a compressed list as an internal implementation , Otherwise, use the hash table as the internal implementation .
I've seen it here , You and I must be predestined friends , Leave your give the thumbs-up and Focus on , It will become a great thing in the future .
边栏推荐
- Redis - how to install redis and configuration (how to quickly install redis on ubuntu18.04 and centos7.6 Linux systems)
- 高质量软件架构的唯一核心指标
- Fisher信息量检测对抗样本代码详解
- Go 语言入门很简单:Go 实现凯撒密码
- Node mongodb installation
- SQL statement syntax error in test SQL statement deletion in eclipse linked database
- Xue Jing, director of insight technology solutions: Federal learning helps secure the flow of data elements
- 三星量产3纳米产品引台媒关注:能否短期提高投入产出率是与台积电竞争关键
- ViewBinding和DataBinding的理解和区别
- #yyds干货盘点# 解决名企真题:连续最大和
猜你喜欢
Openharmony application development how to create dayu200 previewer
MySQL 45 lecture - learn the actual combat notes of MySQL in Geek time 45 lecture - 06 | global lock and table lock_ Why are there so many obstacles in adding a field to the table
Byte interview algorithm question
一个数据人对领域模型理解与深入
When MDK uses precompiler in header file, ifdef is invalid
Efficient! Build FTP working environment with virtual users
近日小结(非技术文)
字节面试算法题
"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
DGraph: 大规模动态图数据集
随机推荐
Apache server access log access Log settings
Use fail2ban to prevent password attempts
Is the outdoor LED screen waterproof?
XML入门一
免费、好用、强大的轻量级笔记软件评测:Drafts、Apple 备忘录、Flomo、Keep、FlowUs、Agenda、SideNote、Workflowy
[AI system frontier dynamics, issue 40] Hinton: my deep learning career and research mind method; Google refutes rumors and gives up tensorflow; The apotheosis framework is officially open source
C language dormitory management query software
模块化笔记软件综合评测:Craft、Notion、FlowUs
Go zero micro service practical series (IX. ultimate optimization of seckill performance)
Using scrcpy projection
js中的变量提升和函数提升
分布式BASE理论
Distributed base theory
Scrapy 框架学习
C basic supplement
C#基础补充
N++ is not reliable
爬虫练习题(一)
Three schemes to improve the efficiency of MySQL deep paging query
XML入门三