Quick List -quicklist Redis data structures

List

In Redisearlier versions, the storage listtime list structure, if the list of elements ranging from the use of compression ziplist, otherwise use a doubly linked listlinkedlist

// list node 
struct listnode <T> { 
    listnode * PREV; 
    listnode * Next; 
    T value; 
} listnode; 
// list 
struct {List 
    listnode * head; // table pointer 
    listNode * tail; // table tail pointer 
    long len; // chain length 
} list;

For the list, we have the following characteristics:

  • Double Ended: with nodes prevand nextpointers to get front, rear node

  • Acyclic: header prevtail table and taildirectedNULL

  • With the tail pointer table header: Get Header table tail node complexityO(1)

  • With chain length counter: obtaining a degree of complexity nodesO(1)

  • Polymorphism: used void*to store the value of the node, different types of values can be stored

Quick List

Linked lists additional space is relatively high, because the 64bitsystem is a pointer 8bytes, prevand the nextpointer must occupy 16bytes, list node and separately allocated in memory, memory fragmentation exacerbated affect the efficiency of memory management.

Considering the above disadvantages linked list, Redissubsequent versions of the transform list data structure, used quicklistin place of ziplistand linkedlist.

// list of nodes quickly 
struct {quicklistNode 
    quicklistNode * PREV; 
    quicklistNode * Next; 
    ziplist * ZL; // list of point compression 
    int32 size; // ziplist total number of bytes 
    int16 count; // ziplist the number of elements 
    int2 encoding; // store form , or represents a primary array of bytes stored in a compressed LZF 
    ... 
} quicklistNode; 
// quick list 
struct {QuickList 
    quicklistNode * head; 
    quicklistNode * Next; 
    Long COUNT; // number of elements 
    int nodes; // number ziplist node 
    int compressDepth ; // LZF compression algorithm depth 
} 
QuickList;

As can be seen from the code, quicklistactually ziplist, and linkedlistmixture thereof, it will linkedlistpress section be segmented, each segment used ziplistfor compact storage, a plurality of ziplisttwo-way series between the pointers.

quicklistInternal default single ziplistlength 8kbyte, will exceed the number of bytes from a new zipliststore.

In the quicklistinterior, to further save space, but also the use of LZFalgorithms to ziplistcompress storage.

By default, quicklistthe compression depth 0i.e. no compression, the actual compression depth by a configuration list-compress-depthdecision.

To support fast pop/push, quicklistand last two ziplistwithout compression, compression case depth 1, depth 2it means the first and second end to end ziplistare not compressed.

Guess you like

Origin www.cnblogs.com/jeemzz/p/11444143.html