Redis storage structure

How is Redis stored?

 This redisDb is a database object. Other fields in it are ignored, and there is a dict list (dictionary list) in it.

Let’s take a look at a redisObject casually

 Let’s make a distinction. There is no redisObject object stored in this dict, nor a dict object. It only stores a data pointer.

Look at every underlying code of redis. If you save this piece again, it will be wasted.

expiration key

Redis data can be set with expiration keys, so that after a certain time, these objects will automatically expire and be recycled. These expired keys are not stored together with the normal keys

Wrong: Ah, this is also a pointer. The keys stored in this dict and expires are the same data. Although the picture is like this, in fact, the timestamp and value can be found in the keys of both dicts (through pointers) 

These two dicts store pointers to key objects (that is, pointers to String objects). One value is an arbitrary object and the other is a timestamp. This key will be reused in the two dicts, so use pointers directly.

Although some of the objects we mentioned before are key-value structures, it does not mean that the key-value structure here is an object. The key here is a string object and the value is an object.  

SET ab, what is the storage structure of this data?

There is a dict in the Redis storage engine, put a at the corresponding offset, and then store b as its corresponding value.

After SET a 100 ex 60, call TTL a. Where is the expiration information stored at this time?
Directly put the key object pointer into expires and then insert the timestamp as value. 

Guess you like

Origin blog.csdn.net/chara9885/article/details/132180036