当前位置:网站首页>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 .
边栏推荐
- 队列的链式存储
- Digital signal processing -- Design of linear phase (Ⅱ, Ⅳ) FIR filter (2)
- Relationship between accuracy factor (DOP) and covariance in GPS data (reference link)
- 阿霍的三个阶段
- localtime居然不可重入,踩坑了
- GID: open vision proposes a comprehensive detection model knowledge distillation | CVPR 2021
- 单点登录SSO与JWT好文整理
- Friends day 2022
- Stack-------
- CPI教程-异步接口创建及使用
猜你喜欢

【邂逅Django】——(二)数据库配置
![leetcode:226. Flip binary tree [DFS flip]](/img/b8/6c5596ac30de59f0f347bb0bddf574.png)
leetcode:226. Flip binary tree [DFS flip]

基于开源流批一体数据同步引擎 ChunJun 数据还原 —DDL 解析模块的实战分享

How to install php7 and perform performance test using yum

工具箱之 IKVM.NET 项目新进展

本科毕业四年:工作,辞职,结婚,买房

STM32 project practice (1) introduction and use of photosensitive resistor

《MATLAB 神经网络43个案例分析》:第40章 动态神经网络时间序列预测研究——基于MATLAB的NARX实现

ROS2 Foxy depthai_ros教程

A hole in solder paste
随机推荐
Chapter 14 signals (IV) - examples of multi process tasks
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
Accept different views with an open mind
Switch basic experiment
Blocking sockets的读写操作该怎么玩?
运行Powershell脚本提示“因为在此系统上禁止运行脚本”解决办法
哪个券商公司开户佣金低又安全又可靠
ASP. Net core 6 from entry to enterprise level practical development application technology summary
BIM and safety in road maintenance-buildSmart Spain
腾讯总考epoll, 很烦
leetcode:241. 为运算表达式设计优先级【dfs + eval】
The sky is blue and misty
CPI教程-异步接口创建及使用
Wechat applet - 80 practical examples of wechat applet projects
【邂逅Django】——(二)数据库配置
系统测试UI测试总结与问题(面试)
基因检测,如何帮助患者对抗疾病?
"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
Ikvm of toolbox Net project new progress
题目 2612: 蓝桥杯2021年第十二届省赛真题-最少砝码(枚举找规律+递推)