当前位置:网站首页>快速整明白Redis中的压缩列表到底是个啥
快速整明白Redis中的压缩列表到底是个啥
2022-07-01 12:36:00 【51CTO】
压缩列表简介
压缩列表(ziplist)是由一个连续内存组成的顺序型数据结构。一个压缩列表可以包含任意多个节点,每个节点上可以保存一个字节数组或整数值。它是Redis为了节省内存空间而开发的。
压缩列表(ziplist)是哈希(hash)和有序集合(zset)的内部编码之一。当哈希(hash)中的元素个数比较少并且每个元素的值占用空间比较小的时候,Redis就会使用压缩列表做为哈希的内部编码。当有序集合(zset)中的元素个数比较少并且每个元素的值占用空间比较小的时候,Redis也会使用压缩列表做为有序集合的内部编码。
压缩列表结构
接下来,我们来看以下压缩列表的内部构造,压缩列表由以下几个部分组成:
zlbytes:表示整个压缩列表占用的内存字节数。xltail:表示压缩列表起始地址到最后一个节点的字节数,可以快速找到最后一个节点。zllength:表示压缩列表包含的节点个数。entries:节点列表,一个挨着一个地紧凑存储。zlend:特殊值0xFF(十进制为255),表示压缩列表的结束。
压缩列表节点结构
每个压缩列表的节点由三部分组成: prevlen、 encoding和content。
prevlen
prevlen:表示该节点前一个节点的字节长度。 prevlen的长度可能是1个字节,也可能是5个字节。
当前一个节点的长度小于254个字节时, prevlen的长度为1个字节,直接存储前一个节点的字节长度;
当前一个节点的长度大于或等于254个字节时, prevlen的长度为5个字节,其中的第一个字节被设置为0xFE,随后的四个字节保存前一个节点的字节长度。
可以通过 prevlen和压缩列表结构中的xltail逆序遍历压缩列表。
encoding
encoding表示该节点中保存数据的类型和长度。
当encoding的最高位以00开头时,表示最大长度为63的短字符串,此时encoding的长度为1个字节,其后面6个位表示字符串的字节长度;
当encoding的最高位以01开头时,表示最大长度为16383的中等长度的字符串,此时encoding的长度为2个字节,其后面14个位表示字符串的字节长度;
当encoding的最高位以10开头时,表示最大长度为4294967295的特长的字符串,此时encoding的长度为5个字节,其后面4个字节表示字符串的字节长度;
当encoding的最高位以11开头时,表示整数值,此时encoding的长度为1个字节,其后面6个位表示整数值的类型和长度。
content
content用于存储节点的值,节点的值可以是一个字节数组,也可以是正数,其类型和长度由encoding决定。
总结
压缩列表(ziplist)是由一个连续内存组成的顺序型数据结构。
一个压缩列表可以包含任意多个节点,每个节点上可以保存一个字节数组或整数值。
压缩列表(ziplist)是哈希(hash)和有序集合(zset)的内部编码之一。
竟然已经看到这里了,你我定是有缘人,留下你的点赞和关注,他日必成大器。
边栏推荐
- 硬阈值(Hard Thresholding)函数解读[通俗易懂]
- A hole in solder paste
- BIM and safety in road maintenance-buildSmart Spain
- 阿霍的三个阶段
- 腾讯总考epoll, 很烦
- Ansi/ul 94 VTM vertical burning test for thin materials
- Sleep quality today 79 points
- [106] 360 check font - check whether the copyright of local Fonts is commercially available
- Tencent Li Wei: deeply cultivate "regulatory technology" to escort the steady and long-term development of the digital economy
- 6.30模拟赛总结
猜你喜欢

Operations related to sequence table
![[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn](/img/f2/7931952b832e84d7b8f2615906f33f.png)
[datawhale202206] pytorch recommendation system: recall model DSSM & youtubednn

Onenet Internet of things platform - mqtt product devices send messages to message queues MQ

Chained storage of queues

项目部署,一点也不难!

2022-06-28-06-29

顺序表有关操作

栈-------

MySQL common functions

ROS2 Foxy depthai_ros教程
随机推荐
晓看天色暮看云,美图欣赏
Mobile note application
Compile and debug net6 source code
Digital signal processing -- Design of linear phase (Ⅱ, Ⅳ) FIR filter (2)
6.30 simulation summary
[20211129] configuration du serveur distant du carnet de notes jupyter
Teach you to complete the actual battle of image classification hand in hand -- Image Recognition Based on convolutional neural network
Need your own cognition
腾讯安全发布《BOT管理白皮书》|解读BOT攻击,探索防护之道
[JS] interview questions
[speech signal processing] 3 speech signal visualization -- prosody
AI matting tool
ROS2 Foxy depthai_ros教程
【脑洞大开】《西潮》及《走向世界丛书》
Huawei interview question: Recruitment
Onenet Internet of things platform - create mqtts products and devices
Wechat applet reports an error: [rendering layer network layer error] pages/main/main Local resource pictures in wxss cannot be obtained through wxss. You can use network pictures, Base64, or < image/
Ipv6-6to4 experiment
"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
[JS advanced] promise explanation