Redis Design and Implementation Study Notes
Preface
This book focuses on the implementation of the underlying Redis layer, which is divided into four parts:
- Data Structure and Object
- Standalone Database implementation
- Implementation of multi-machine Databases
- Independent Functions
This sequence should be the same as the sequence learned by the author, but it seems a bit unreasonable: I was always in a hurry at the beginning, this is because you have no idea about Redis as a whole.
Redis design and implementation version 2 hd pdf download
Study Notes
In Redis, the key is a string and the value is an object. The data structures used for underlying processing include:
- Dynamic string: uses pre-allocation and inert release to reduce the number of memory operations
- Linked List
- Dictionary: Progressive rehash to prevent getting stuck
- Skip table
- Integer Set: an ordered and non-repeating Integer Set, which can be upgraded as necessary to save memory.
- Compressed list: stores the list of integers or bytes in the continuous memory, and saves memory by compressing them.
- Object: all objects in Redis are implemented based on the above data structure
Because Redis is written in C and there is no garbage collection mechanism, a reference counting implementation memory recycler is built in the object system. Through this mechanism, the program can automatically release the object and recycle the memory when appropriate by tracking the reference counting information of the object.
With these foundations, you can start to see how Redis works as a server:
+-------------+ | redisServer | +------+------+ | +-----------+ +------+------+ +-----------+|redisClient+-----+ redisDb +--+---+ dict |+-----------+ +-------------+ | +-----------+ | redisDb | | +-------------+ | +-----------+ | redisDb | +---+ expires | +-------------+ +-----------+
Where:
- Dict: key space
- Expires: Key expiration time
Another method of expiration time is to extend the key on dict and add the expiration time field. Compared with Redis's practice, there may be several disadvantages: waste of space, time-consuming, and unclear structure. There are three policies for deleting expired keys:
- Scheduled deletion: Timer is created when the key expiration time is set and deleted when the Timer is running.
- Inert deletion: determines whether it expires when the value is set. If it expires, it is deleted.
- Regular deletion: checks and scans the database at intervals to delete expired keys.
Regular deletion is obviously unreliable. Regular deletion and inert deletion are also used in Redis. Of course, the expiration time must be considered in the persistence program.
You may also like the following articles about Redis. For details, refer:
Install and test Redis in Ubuntu 14.04
Basic configuration of Redis master-slave Replication
Redis cluster details
Install Redis in Ubuntu 12.10 (graphic explanation) + Jedis to connect to Redis
Redis series-installation, deployment, and maintenance
Install Redis in CentOS 6.3
Learning notes on Redis installation and deployment
Redis. conf
Redis details: click here
Redis: click here
This article permanently updates the link address: