redis-lists
关于 redis lists 类型
https://redis.io/topics/data-types-intro
lists 相关操作命令 : https://redis.io/commands#list
根据文档中的关于 lists 的简介 为 其基于 linked list 数据结构
对于链表(双向链表)数据结构,对于链表的相关操作包含以下特点
- 新增节点时间复杂度为 O(1)
- 对于查询/删除/更新操作其时间复杂度为 O(n) ,对于 删除/更新操作主要是因为查询的时间复杂度,对于实际的删除/更新操作时间复杂度为o(1) , 由于定位指定节点的时间复杂度为 O(n)
redis 相关内存优化配置
https://redis.io/topics/memory-optimization
对于其 lists 底层数据结构优化
相关配置: https://redis.io/topics/config
redis 6.0 conf : https://raw.githubusercontent.com/redis/redis/6.0/redis.conf
关于 配置 "list-max-ziplist-size -2" 设置每个 element 的大小自适应设置限制数据量,其通过对数据进行特殊编码进行节省空间;
关于配置 "list-compress-depth 0" 设置是否使用 数据压缩
关于 ziplist 源码 :https://github.com/redis/redis/blob/unstable/src/ziplist.c
重点在于其开头注释
根据其注释可以看到其实际是一个特殊的双向链表,但其进行了相关的压缩操作,并通过记录每个节点的信息实现快速查找
其 结构特点为 "<zlbytes> <zltail> <zllen> <entry> <entry> ... <entry> <zlend>"
/* We use this function to receive information about a ziplist entry. * Note that this is not how the data is actually encoded, is just what we * get filled by a function in order to operate more easily. */ typedef struct zlentry { unsigned int prevrawlensize; /* Bytes used to encode the previous entry len*/ unsigned int prevrawlen; /* Previous entry len. */ unsigned int lensize; /* Bytes used to encode this entry type/len. For example strings have a 1, 2 or 5 bytes header. Integers always use a single byte.*/ unsigned int len; /* Bytes used to represent the actual entry. For strings this is just the string length while for integers it is 1, 2, 3, 4, 8 or 0 (for 4 bit immediate) depending on the number range. */ unsigned int headersize; /* prevrawlensize + lensize. */ unsigned char encoding; /* Set to ZIP_STR_* or ZIP_INT_* depending on the entry encoding. However for 4 bits immediate integers this can assume a range of values and must be range-checked. */ unsigned char *p; /* Pointer to the very start of the entry, that is, this points to prev-entry-len field. */ } zlentry;关于 entry 的定义
关于quicklist
https://github.com/redis/redis/blob/unstable/src/quicklist.c
A doubly linked list of ziplists

浙公网安备 33010602011771号