当前位置:网站首页>Quickly understand what the compressed list in redis is
Quickly understand what the compressed list in redis is
2022-07-01 12:40:00 【51CTO】
Introduction to compressed list
Compressed list (ziplist) It is a sequential data structure composed of a continuous memory . A compressed list can contain any number of nodes , A byte array or integer value can be saved on each node . It is Redis Developed to save memory space .
Compressed list (ziplist) It's hash (hash) And ordered set (zset) One of the internal codes of . When hash (hash) When the number of elements in is relatively small and the value of each element takes up less space ,Redis The compressed list will be used as the internal encoding of the hash . When ordered set (zset) When the number of elements in is relatively small and the value of each element takes up less space ,Redis Compressed lists are also used as the internal encoding of ordered sets .
Compressed list structure
Next , Let's look at the internal structure of the following compressed list , The compressed list consists of the following parts :
zlbytes: Indicates the number of memory bytes occupied by the whole compressed list .xltail: Indicates the number of bytes from the starting address of the compressed list to the last node , You can quickly find the last node .zllength: Indicates the number of nodes contained in the compressed list .entries: The node list , Compact storage one by one .zlend: Special values 0xFF( Decimal system 255), Indicates the end of the compressed list .
Compress list node structure
The node of each compressed list consists of three parts : prevlen、 encoding and content.
prevlen
prevlen: Indicates the byte length of the previous node of the node . prevlen The length of may be 1 Bytes , It could be 5 Bytes .
The length of the current node is less than 254 Bytes , prevlen The length of is 1 Bytes , Directly store the byte length of the previous node ;
The length of the current node is greater than or equal to 254 Bytes , prevlen The length of is 5 Bytes , The first byte is set to 0xFE, The next four bytes save the byte length of the previous node .
Can pass prevlen And... In the compressed list structure xltail Traverse the compressed list in reverse order .
encoding
encoding Indicates the type and length of data saved in this node .
When encoding The highest order of 00 At the beginning , Indicates that the maximum length is 63 Short string of , here encoding The length of is 1 Bytes , Behind it 6 Bits represent the byte length of the string ;
When encoding The highest order of 01 At the beginning , Indicates that the maximum length is 16383 Medium length string , here encoding The length of is 2 Bytes , Behind it 14 Bits represent the byte length of the string ;
When encoding The highest order of 10 At the beginning , Indicates that the maximum length is 4294967295 Special long string , here encoding The length of is 5 Bytes , Behind it 4 Bytes represent the byte length of the string ;
When encoding The highest order of 11 At the beginning , Represents integer value , here encoding The length of is 1 Bytes , Behind it 6 Bits indicate the type and length of the integer value .
content
content The value used for the storage node , The value of a node can be an array of bytes , It can also be a positive number , Its type and length are determined by encoding decision .
summary
Compressed list (ziplist) It is a sequential data structure composed of a continuous memory .
A compressed list can contain any number of nodes , A byte array or integer value can be saved on each node .
Compressed list (ziplist) It's hash (hash) And ordered set (zset) One of the internal codes of .
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 .
边栏推荐
- Chain storage of binary tree
- (mixed version 1) multiple TXT text to one table
- The difference between memcpy and strcpy
- AI matting tool
- 手把手教你完成图像分类实战——基于卷积神经网络的图像识别
- 腾讯总考epoll, 很烦
- Fatal error: execution: there is no such file or directory
- Ansible相关内容梳理
- 【20211129】Jupyter Notebook遠程服務器配置
- [Suanli network] technological innovation of Suanli Network -- key technology of operation service
猜你喜欢
![[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE](/img/8f/64fea641730795a2b5252cc2c8cdd2.png)
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
![[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn](/img/f2/7931952b832e84d7b8f2615906f33f.png)
[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn

How to use opcache, an optimization acceleration component of PHP
![[some notes]](/img/91/7657f90b50f012736579b1585b4ade.jpg)
[some notes]
![[datawhale202206] pytorch recommendation system: precision model deepfm & DIN](/img/4f/8799016731a2c1647b6f2f4d96b754.png)
[datawhale202206] pytorch recommendation system: precision model deepfm & DIN

2022-06-28-06-29

Use Net core access wechat official account development

【脑洞大开】《西潮》及《走向世界丛书》
![[Suanli network] technological innovation of Suanli Network -- key technology of operation service](/img/80/6e3648c88d309516d4bc29db9c153c.jpg)
[Suanli network] technological innovation of Suanli Network -- key technology of operation service

Nc100 converts strings to integers (ATOI)
随机推荐
下半年还有很多事要做
Ansible Playbook
JS related interview questions and answers (1)
腾讯总考epoll, 很烦
redis探索之缓存一致性
System test UI test summary and questions (interview)
Chain storage of binary tree
快速整明白Redis中的压缩列表到底是个啥
第十四章 信号(四)- 多进程任务示例
木架的场景功能
数论基础及其代码实现
(混更一篇)多个txt文本转一个表格
leetcode:241. 为运算表达式设计优先级【dfs + eval】
[JS] interview questions
Compile and debug net6 source code
kubernetes之ingress探索实践
【MAUI】为 Label、Image 等控件添加点击事件
Wechat simulated geographical location_ Camouflage wechat location
Ikvm of toolbox Net project new progress
How to install php7 and perform performance test using yum