Redis Design and Implementation Study Notes

Source: Internet
Author: User
Tags redis cluster install redis

Redis Design and Implementation Study Notes
Preface

This book focuses on the implementation of the underlying Redis layer, which is divided into four parts:

  1. Data Structure and Object
  2. Standalone Database implementation
  3. Implementation of multi-machine Databases
  4. 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:

  1. Dynamic string: uses pre-allocation and inert release to reduce the number of memory operations
  2. Linked List
  3. Dictionary: Progressive rehash to prevent getting stuck
  4. Skip table
  5. Integer Set: an ordered and non-repeating Integer Set, which can be upgraded as necessary to save memory.
  6. Compressed list: stores the list of integers or bytes in the continuous memory, and saves memory by compressing them.
  7. 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:

  1. Dict: key space
  2. 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:

  1. Scheduled deletion: Timer is created when the key expiration time is set and deleted when the Timer is running.
  2. Inert deletion: determines whether it expires when the value is set. If it expires, it is deleted.
  3. 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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.