Redis的列表(List)底層實現之一由鏈表實現,當一個列表包含了數量比較多的元素,又或者列表中包含的元素都是比較長的字符串時,Redis使用鏈表做爲列表的底層實現。函數
除了列表外,發佈訂閱、慢查詢、監視器等功能都用到了鏈表。code
鏈表Node結構源代碼,adlist.h/listNode:字符串
typedef struct listNode { //前置節點 struct listNode *prev; //後置節點 struct listNode *next; //節點值 void *value; } listNode;
adlist.h/list源代碼:class
typedef struct list { //表頭節點 listNode *head; //表尾節點 listNode *tail; //長度 unsigned long len; //節點複製函數 void *(*dup) (void *ptr); //節點釋放函數 void *(*free) (void *ptr); //節點值對比函數 int (*match) (void *ptr, void *key); } list;