Redis data storage model
redisObject
typedef struct redisObject {
unsigned type:4;
unsigned encoding:4;
unsigned lru:LRU_BITS; /* LRU time (relative to global lru_clock) or
* LFU data (least significant 8 bits frequency
* and most significant 16 bits access time). */
int refcount;
void *ptr;
} robj;
Defines the data object structure in Redis redisObject
, which is the basic unit for Redis to store data.
-
unsigned type:4;
andunsigned encoding:4;
: These two fields are used to represent the type and encoding of the object. They each use 4 bits for storage, so the value of each field can be from 0 to 15 (a 4-bit binary number can represent a decimal number from 0 to 15).type
Represents the data type of the object (such as string, hash, list, etc.), andencoding
represents the internal encoding method of the object (for example, the encoding method of the string can be int, embstr, etc.). -
unsigned lru:LRU_BITS;
: This field is used to implement the LRU (Least Recently Used) algorithm and is used for object elimination strategy.LRU_