Eighth. Redis database structure and read-write principle

Source: Internet
Author: User
Tags redis server

Note: This article mainly refers to the design and implementation of Redis

1. Database structure

Each REDIS server internal data structure is a redisdb[], the size of the array can be configured in redis.conf ("Database 16", the default is 16), and all our cache operations (Set/hset/get, etc.) are in the Redisdb [] on one of the Redisdb (libraries), the REDISDB default is redisdb[0].

Note :

    • The next operation can be selected via "Select 1" on redisdb[1]
    • In actual use, we only operate on redisdb[0] , because
      • Redis does not get the function that is currently operating on which Redisdb, so it is easy to select multiple times, we do not know which library, and since it is only on the redisdb[0] operation, then "database" can be set to 1,
      • After this parameter is set to 1, not only can the original memory of other redisdb to Redisdb[0], in the "periodic delete" policy, we also only scan a redisdb on it.

"Delete periodically" see Nineth. Redis Expiration Policy

2. Principle of reading and writing

In each redisdb, a dict (dictionary) is used to store "Key-value".

Example:

Assume that the following four commands are executed in Redis and no select is executed, that is, the default choice is to operate on redisdb[0]

Set msg "Hello Nana"

Rpush mylist "A" "B" "C"

Hset Book name "Lover"

Hset book author "Nana"

The storage structure is as follows:

3. Maintenance work performed while reading and writing

After reading a key (read-write operation requires reading key),

    • Server update cache Hit count and number of misses
    • Update the last use time of the key
    • Detects if the key is out of date (see Chapter Nineth Redis Expiration policy for details)
    • Write counter +1 for persistence

Eighth. Redis database structure and read-write principle

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.