当前位置:网站首页>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 .
边栏推荐
- 队列的链式存储
- VS Code 设置代码自动保存
- 6.30 simulation summary
- Mobile note application
- 本科毕业四年:工作,辞职,结婚,买房
- "Analysis of 43 cases of MATLAB neural network": Chapter 40 research on prediction of dynamic neural network time series -- implementation of NARX based on MATLAB
- Double linked list related operations
- IOS interview
- 类的初始化与实例化
- 基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
猜你喜欢
随机推荐
Three stages of aho
使用nvm管理nodejs(把高版本降级为低版本)
2022-06-28-06-29
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
【20211129】Jupyter Notebook遠程服務器配置
项目部署,一点也不难!
第十四章 信号(四)- 多进程任务示例
微信小程序 – 80个实用的微信小程序项目实例
[Suanli network] technological innovation of Suanli Network -- key technology of operation service
BIM and safety in road maintenance-buildSmart Spain
ustime写出了bug
下半年还有很多事要做
Efforts at the turn of the decade
买卖其实也有风险
腾讯安全联合毕马威发布监管科技白皮书,解析“3+3”热点应用场景
工具箱之 IKVM.NET 项目新进展
Queue operation---
天青色等烟雨
Question d'entrevue de Huawei: recrutement
[JS advanced] promise explanation
![[some notes]](/img/91/7657f90b50f012736579b1585b4ade.jpg)




![[encounter Django] - (II) database configuration](/img/13/9512c1e03349092874055771c3433d.png)



