redis-design and implementation-linked list

Redis

Linked list

effect

  1. Low-level implementation of list keys
  2. Publish and subscribe, slow query, monitor function implementation
  3. Save multiple client status information
  4. Build the client output buffer

Linked list and linked list node realization

  • Node
typedef struct listNode {
    struct listNode *prev; // 前置节点
    struct listNode *next; // 后置节点
    void *value; // 值
}
  • list
typedef struct list {
    listNode *head; // 表头
    listNode *tail; // 表尾
    unsigned long len; // 节点数量
    void *(*dup)(void *ptr); // 节点值复制函数
    void *(*free)(void *ptr); // 节点值释放函数
    int (*match)(void *ptr, void *key); // 节点值对比函数
}

feature

  • Double ended
  • Acyclic
  • With head and tail pointer
  • Length counter with linked list
  • Polymorphism: The linked list node uses the void* pointer to save the node value, and different values ​​can be set through the three operation methods of the list, so the linked list can be used to save various types of values

Guess you like

Origin blog.csdn.net/DALAOS/article/details/114141207