当一个列表键包含了数量比较多的元素,又或者列表中包含的的元素都是比较长的字符串,Redis就会使用链表作为列表键的底层实现
每个列表节点的数据结构为
列表数据接口中保存了 该节点前置节点的指针、后置节点的指针、和当前节点值的指针 如果值为字符串则指向sds数据结构
列表数据结构
head 为头指针指向第一个节点元素,
tail为指针指向列表的最后一个元素
len 列表中元素的个数
llen函数时间复杂度为O(1)
获取列头和列尾的时间复杂度为O(1)获取当前元素的下一个元素和上一个元素的时间复杂度为O(1)
获取某个元素的时间复杂度为O(n)
除了列表的底层会使用链表数据结构,像发布与订阅、慢查询、监视器等