Redis object details, redis object details
1: redis stores keys and key values through objects. The objects are composed of basic types such as sds/linked list/Dictionary/skip table/Integer collection/compressed list. 2: redis corresponds to the memory collection mechanism based on reference count. When the reference count of an object is zero, the object will be more than recycled. Objects can be shared through reference counting. Object sharing is mainly because multiple database keys can share one object to save memory.
3: The redis object has access time record information. When maxmemory is used on the server, keys that have not been used for a long time will be preferentially deleted. redis uses redisobject to represent an object.
Typedef struct redisObject {unsigned type: 4; // using object encoding, you can see the encoding unsigned encoding: 4 for the key value; // The last access time, object idletime does not modify the lru value of the object unsigned lru: REDIS_LRU_BITS;/* lru time (relative to server. lruclock) * // reference count. When the reference count is zero, the object may be recycled int refcount; // void * ptr pointing to the actual value;} robj; the type is/* Object types */# define REDIS_STRING 0 # define REDIS_LIST 1 # define REDIS_SET 2 # define REDIS_ZSET 3 # define RE DIS_HASH 4 # define limit 9 # define REDIS_LIST_ZIPLIST 10 # define limit 11 # define limit 12 # define REDIS_HASH_ZIPLIST 13 where the endoding is # define limit 0/* Raw representation */# define limit 1 /* Encoded as integer */# define REDIS_ENCODING_ZIPMAP 2/* Encoded as zipmap */# define REDIS_ENCODING_HT 3/* Encoded as a hash table */For example, the following function can add object references. calculation Void incrRefCount (robj * o) {o-> refcount ++;} For redis databases, keys are always of the sds type, and key values can be either of the following, therefore, the type of the key-value object is returned using the type command. The main operation commands for string objects are: set/get/append/incrbyfloat/incrby/decrby/strlen/setrange/getrange list object. The main operation commands are as follows: the main commands for lpush/rpush/lpop/rpop/lindex/linsert/lrem/ltrim/lset hash objects are: the main commands for hset/hget/hexists/hdel/hlen/hgetall collection objects are: sadd/scard/sismember/smembers/srandmember/spop/srem ordered object: zadd/zcard/zcount/zrange/zrevrange/zrank/zrevrank/zrem/zcore also has a class of commands for all types. For example, redis, such as del/expire/rename/type/object, will share 0 ~ 9999 String object.