Redis系列之底层数据结构ZipList
实验环境
- Redis 6.0
什么是Ziplist?
Ziplist,压缩列表,这种数据结构会根据存入数据的类型和大小,分配大小不同的空间,所以是为了节省内存而采用的。因为这种数据结构是一种完整连续的数据单元,所以一旦发生数据改变,会产生连锁更新,严重影响访问性能,所以这种数据结构只适应于数据量比较小的情况。
ZipList可以存储字符串或者整数,存储整数时是采用整数的二进制而不是字符串形式存储。
ZipList数据结构
在Redis的源码找到ziplist.c,链接:https://github.com/redis/redis/blob/6.0/src/ziplist.c
/* The ziplist is a specially encoded dually linked list that is designed
* to be very memory efficient. It stores both strings and integer values,
* where integers are encoded as actual integers instead of