当前位置:网站首页>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 .
边栏推荐
- 微信模拟地理位置_伪装微信地理位置
- Tencent security released the white paper on BOT Management | interpreting BOT attacks and exploring ways to protect
- Digital signal processing -- Design of linear phase (Ⅱ, Ⅳ) FIR filter (2)
- Like the three foot platform
- Blue Bridge Cup multi interface switching processing (enumeration plus state machine method)
- 基于开源流批一体数据同步引擎 ChunJun 数据还原 —DDL 解析模块的实战分享
- Sort out relevant contents of ansible
- Huawei interview question: Recruitment
- localtime居然不可重入,踩坑了
- 工具箱之 IKVM.NET 项目新进展
猜你喜欢
使用nvm管理nodejs(把高版本降级为低版本)
leetcode:329. The longest incremental path in the matrix [DFS + cache + no backtracking + elegance]
[brain opening] west tide and going to the world series
MySQL workbench data modeling function
How to install php7 and perform performance test using yum
BIM and safety in road maintenance-buildSmart Spain
Common chart usage of Bi tools
Operations related to sequence table
[encounter Django] - (II) database configuration
leetcode:226. Flip binary tree [DFS flip]
随机推荐
MySQL workbench data modeling function
華為面試題: 招聘
BIM and safety in road maintenance-buildSmart Spain
【历史上的今天】7 月 1 日:分时系统之父诞生;支付宝推出条码支付;世界上第一支电视广告
[20211129] jupyter notebook remote server configuration
Nc100 converts strings to integers (ATOI)
使用BurpSuite对app抓包教程
What are the PHP FPM configuration parameters
VS Code 设置代码自动保存
I wish you all a happy reunion
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
QT 播放器之列表[通俗易懂]
高薪程序员&面试题精讲系列118之Session共享有哪些方案?
MySQL的零拷贝技术
IOS interview
Stack-------
腾讯安全联合毕马威发布监管科技白皮书,解析“3+3”热点应用场景
Huawei interview question: Recruitment
ASTM D 3801固体塑料垂直燃烧试验
系统测试UI测试总结与问题(面试)