【Redis对象】
redis.h
/*
* redis对象
*/
typedef struct redisObject {
// 对象的类型(取值范围:REDIS_STRING, REDIS_LIST, REDIS_HASH, REDIS_SET, REDIS_ZSET)
unsigned type:4;
// 对象的编码(取值范围:REDIS_ENCODING_INT, REDIS_ENCODING_EMBSTR, REDIS_ENCODING_RAW, REDIS_ENCODING_HT, REDIS_ENCODING_LINKEDLIST,REDIS_ENCODING_ZIPLIST,REDIS_ENCODING_INTSET,REDIS_ENCODING_SKIPLIST)
unsigned encoding:4;
// 指向底层实现数据结构的指针
void *ptr;
unsigned notused:2; /* Not used */
unsigned lru:22; /* lru time (relative to server.lruclock) */
int refcount;
} robj;
每当我们在redis中新建一个键值对的时候,我们至少会创建两个对象:一个是key的对象,一个是value的对象。key对象总是一个字符串类型的对象,而值对象,则会是5种对象类型中的任意一种。 如下图所示:
127.0.0.1:6379> set muse java
OK
127.0.0.1:6379> type muse
string
127.0.0.1:6379> rpush queue 1 3 4 5
(integer) 4
127.0.0.1:6379> type queue
list
【encoding编码】
127.0.0.1:6379> OBJECT encoding muse
"embstr"