Redis linked list implementation

Time:2021-10-13
//Each linked list node uses a listnode structure to represent a typedef struct listnode{
    //Front node
    struct ListNode *prev;
    //Post node
    struct ListNode *next;
    //Node value
    void *value;
} ListNode;

  

// 
typedef struct List{
    //Head node
    struct ListNode *head;
    //Tail node
    struct ListNode *tail;
    //Number of nodes contained in the linked list
    unsigned long length; // node value replication function void * (* DUP) (void * PTR);
//Node value release function void * (* FREE) (void * PTR);
//Node value comparison function void (* match) (void * PTR, void * key);
} List;

The features of redis linked list implementation are summarized as follows:

  1. Double ended: the linked list node has prev and next pointers to obtain the pre node and post node of a node
  2. Acyclic: the prev pointer of the header node and the next pointer of the footer node point to null, so the access to the linked list is terminated with null and acyclic
  3. Pointer with header and footer: through the tail and head pointers of the list, the complexity of obtaining the header and footer nodes of the linked list is O (1)
  4. With linked list length counter: through the length attribute of the list, the time complexity of obtaining the length of the linked list is O (1)
  5. Polymorphism: the linked list node uses the void * pointer to save the node value, and can set type specific functions for the node value through the DUP, free and match attributes of the list structure, so the linked list can be used to save various types of values.

Linked list is used to realize various functions of redis, such as list key, publish and subscribe, slow query, monitor, etc

Recommended Today

SQL exercise 20 – Modeling & Reporting

This blog is used to review and sort out the common topic modeling architecture, analysis oriented architecture and integration topic reports in data warehouse. I have uploaded these reports to GitHub. If you are interested, you can have a lookAddress:https://github.com/nino-laiqiu/TiTanI recorded a relatively complete development process in my hexo blog deployed on GitHub. You can […]