当前位置:网站首页>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 .
边栏推荐
- The difference between memcpy and strcpy
- System test UI test summary and questions (interview)
- 晓看天色暮看云,美图欣赏
- leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】
- Three stages of aho
- MySQL的零拷贝技术
- Eurake partition understanding
- redis探索之缓存一致性
- Four years after graduation: work, resign, get married, buy a house
- 【20211129】Jupyter Notebook遠程服務器配置
猜你喜欢
Ikvm of toolbox Net project new progress
【邂逅Django】——(二)数据库配置
I wish you all a happy reunion
[datawhale202206] pytorch recommendation system: precision model deepfm & DIN
79. 单词搜索【dfs + 回溯visit + 遍历起点】
Arm GIC (V) how arm TrustZone supports security interrupt analysis notes.
Ansible相关内容梳理
How to install php7 and perform performance test using yum
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
leetcode:329. The longest incremental path in the matrix [DFS + cache + no backtracking + elegance]
随机推荐
数字信号处理——线性相位型(Ⅱ、Ⅳ型)FIR滤波器设计(2)
数论基础及其代码实现
Sort out relevant contents of ansible
The difference between memcpy and strcpy
Question d'entrevue de Huawei: recrutement
The sky is blue and misty
Which securities company has a low, safe and reliable account opening commission
ASTM D 3801固体塑料垂直燃烧试验
[speech signal processing] 3 speech signal visualization -- prosody
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE
买卖其实也有风险
微信模拟地理位置_伪装微信地理位置
Common chart usage of Bi tools
logstash报错:Cannot reload pipeline, because the existing pipeline is not reloadable
[Yu Yue education] financial management reference materials of Ningbo University of Finance and Economics
華為面試題: 招聘
CPI tutorial - asynchronous interface creation and use
【历史上的今天】7 月 1 日:分时系统之父诞生;支付宝推出条码支付;世界上第一支电视广告
Ikvm of toolbox Net project new progress
ustime写出了bug