Chapter 8 Redis database structure and read/write Principles, chapter 8 redis

Source: Internet
Author: User

Chapter 8 Redis database structure and read/write Principles, chapter 8 redis

Note: This article mainly references Redis Design and Implementation

1. Database Structure

The internal data structure of each redis Server is a redisDb []. The size of this array can be found in redis. configuration in conf ("database 16", default value: 16), and all our cache operations (set/hset/get) are a redisDb (database) in redisDb) the redisDb is redisDb [0] by default.

Note::

  • You can use "select 1" to select the next operation on redisDb [1 ].
  • In actual use, we only operate on redisDb [0], because
    • Redis does not obtain the current redisDb operation function, so it is easy to select multiple times, we do not know which database, and since the operation is only performed on redisDb [0], "database" can be set to 1,
    • After this parameter is set to 1, you can not only allocate the memory occupied by the original redisDb to redisDb [0], but also in the "Regular deletion" policy, we can scan only one redisDb.

"Regular deletion" see Chapter 9 Redis expiration Policy

 

2. read/write principles

In each redisDb, A dict (dictionary) is used to store "key-value ".

Example:

If the following four commands are executed in redis and no select is executed, the redisDb [0] operation is selected by default.

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 during read/write operations

After reading a key (The key must be read for both read and write operations,

  • Server Update cache hits and missed hits
  • Last time used to update the key
  • Check whether the key has expired (For details, refer to Chapter 9 Redis Expiration Policy)
  • Write counter + 1 for persistence

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.