当前位置:网站首页>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 .
边栏推荐
- 使用宝塔部署halo博客
- Three schemes to improve the efficiency of MySQL deep paging query
- CTF competition problem solution STM32 reverse introduction
- Oracle 被 Ventana Research 评为数字创新奖总冠军
- Samsung's mass production of 3nm products has attracted the attention of Taiwan media: whether it can improve the input-output rate in the short term is the key to compete with TSMC
- Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
- C语言集合运算
- WS2811 M是三通道LED驱动控制专用电路彩灯带方案开发
- N++ is not reliable
- Go 语言入门很简单:Go 实现凯撒密码
猜你喜欢
ASP.NET Core入门一
How real-time cloud interaction helps the development of education industry
8 expansion sub packages! Recbole launches 2.0!
逆向调试入门-PE结构-资源表07/07
Source code compilation and installation of MySQL
Commvault 和 Oracle 合作,在 Oracle 云上提供 Metallic数据管理即服务
CTF competition problem solution STM32 reverse introduction
如何在 2022 年为 Web 应用程序选择技术堆栈
上汽大通MAXUS正式发布全新品牌“MIFA”,旗舰产品MIFA 9正式亮相!
聊聊支付流程的设计与实现逻辑
随机推荐
"Pre training weekly" issue 52: shielding visual pre training and goal-oriented dialogue
Getting started with the go language is simple: go implements the Caesar password
C語言宿舍管理查詢軟件
Getting started with microservices
高效!用虚拟用户搭建FTP工作环境
动画与过渡效果
一个数据人对领域模型理解与深入
Redis —— How To Install Redis And Configuration(如何快速在 Ubuntu18.04 与 CentOS7.6 Linux 系统上安装 Redis)
CTF competition problem solution STM32 reverse introduction
光环效应——谁说头上有光的就算英雄
C语言程序设计选题参考
Iptables foundation and Samba configuration examples
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
Read the BGP agreement in 6 minutes.
PostgreSQL 9.1 soaring Road
remount of the / superblock failed: Permission denied
如何在 2022 年为 Web 应用程序选择技术堆栈
Solution: how to delete the information of Jack in two tables with delete in one statement in Oracle
2022G3锅炉水处理考试题模拟考试题库及模拟考试
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example