typedefstructredisObject { 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;
/* The "module" object type is a special one that signals that the object * is one directly managed by a Redis module. In this case the value points * to a moduleValue struct, which contains the object value (which is only * handled by the module itself) and the RedisModuleType struct which lists * function pointers in order to serialize, deserialize, AOF-rewrite and * free the object. * * Inside the RDB file, module types are encoded as OBJ_MODULE followed * by a 64 bit module type ID, which has a 54 bits module-specific signature * in order to dispatch the loading to the right module, plus a 10 bits * encoding version. */ #define OBJ_MODULE 5 /* Module object. */ #define OBJ_STREAM 6 /* Stream object. */
redis的编码分类
1 2 3 4 5 6 7 8 9 10 11
#define OBJ_ENCODING_RAW 0 /* Raw representation */ #define OBJ_ENCODING_INT 1 /* Encoded as integer */ #define OBJ_ENCODING_HT 2 /* Encoded as hash table */ #define OBJ_ENCODING_ZIPMAP 3 /* Encoded as zipmap */ #define OBJ_ENCODING_LINKEDLIST 4 /* No longer used: old list encoding. */ #define OBJ_ENCODING_ZIPLIST 5 /* Encoded as ziplist */ #define OBJ_ENCODING_INTSET 6 /* Encoded as intset */ #define OBJ_ENCODING_SKIPLIST 7 /* Encoded as skiplist */ #define OBJ_ENCODING_EMBSTR 8 /* Embedded sds string encoding */ #define OBJ_ENCODING_QUICKLIST 9 /* Encoded as linked list of ziplists */ #define OBJ_ENCODING_STREAM 10 /* Encoded as a radix tree of listpacks */
1 2 3 4 5 6 7 8 9 10 11 12 13 14
char *strEncoding(int encoding){ switch(encoding) { case OBJ_ENCODING_RAW: return"raw"; case OBJ_ENCODING_INT: return"int"; case OBJ_ENCODING_HT: return"hashtable"; case OBJ_ENCODING_QUICKLIST: return"quicklist"; case OBJ_ENCODING_ZIPLIST: return"ziplist"; case OBJ_ENCODING_INTSET: return"intset"; case OBJ_ENCODING_SKIPLIST: return"skiplist"; case OBJ_ENCODING_EMBSTR: return"embstr"; case OBJ_ENCODING_STREAM: return"stream"; default: return"unknown"; } }
typedefstructquicklist { quicklistNode *head; quicklistNode *tail; unsignedlong count; /* total count of all entries in all ziplists */ unsignedlong len; /* number of quicklistNodes */ int fill : QL_FILL_BITS; /* fill factor for individual nodes */ unsignedint compress : QL_COMP_BITS; /* depth of end nodes not to compress;0=off */ unsignedint bookmark_count: QL_BM_BITS; quicklistBookmark bookmarks[]; } quicklist;
#根据score范围查询 #zrangebyscore key min max [WITHSCORES] [LIMIT offset count] zrangebyscore zset2 0 1
#根据score的范围来计数 #zcount key min max zcount zset2 0 10 #根据值来获取下标(根据score从小到大来排的序) #zrank key member zrank zset2 d #根据值来获取下标(根据score从大到小来排的序) #zrevrank key member zrevrank zset2 d #根据值来获取score #zscore key member zscore zset2 c