current position:Home>gDvuGqjmDS


2022-05-15 07:42:17Java hobby maniac

stay Redis in , There is a data type , When the data is stored, two data structures will be used to store them separately , that Redis Why do that ? Will this cause the same piece of data to take up twice as much space ?

Five basic types of set objects
Redis The collection object in is an unordered collection of string type elements , The elements in the set are unique and unrepeatable .

There are two underlying data structures for collection objects :intset and hashtable. The interior is differentiated by coding :

intset code
intset( Set of integers ) It can be saved as int16_t,int32_t,int64_t The integer value , And make sure there are no duplicate elements in the collection .

intset The data structure is defined as follows ( Source code inset.h Inside ):

typedef struct intset {
    uint32_t encoding;// Encoding mode
    uint32_t length;// The number of elements in the current set
    int8_t contents[];// Specific elements in a collection
} intset;
Here is a intset Collection object storage diagram of :


Link to the original text :

copyright notice
author[Java hobby maniac],Please bring the original link to reprint, thank you.

Random recommended