Redis Topic Two: RDB and AOF persistence

Source: Internet
Author: User
Tags redis server

Databases in the server
    • The Redis server saves all the databases in the DB array of the server state structure, and each item in the DB array is a REDISDB structure, and the length of an array of REDISDB structures represents the number of databases. The target database for Redis is database number No. 0 by default, but clients can switch databases by executing the SELECT command

      Inside the server, the DB attribute of the client state redisclient structure records the client's current target database, which is a pointer to Redisdb
typedef struct redisClient{    //...    //记录客户端当前正在使用的数据库    redisDb *db;} redisClient;db[0],db[1],db[2],db[n]客户端通过改变redisClient.db的指针,让它指向服务器中的不同数据库,从而实现切换目标数据库的功能。这就是SELECT实现的原理struct redisServer{    //...    //一个数组,保存着服务器中的所有数据库    reddisDb *db;    //服务器的数据库数量    int dbnum;    //...}db[0],db[1],db[2],db[n]
Persistence of
    • Because Redis is an in-memory database, it stores its own database state in memory. So if the data stored in memory is not even written to disk, then the server outage data will all disappear. The essence of persistence is to write data to disk to ensure that the data is "persistent".

    • Why put the data in memory? This is the difference between Redis and other relational databases, although the relational database (for example, MySQL) also has some data put into memory, but only part, in order to improve the cache hit rate MySQL will put the common data in memory (buffer cache), This allows you to minimize the number of times the database goes to disk to read data, because in a single physical I/O, the disk seek occupies an overwhelming portion of the total time spent reading the data, and we want more read and write to be logical I/O (memory read-write) rather than physical I/O. So Redis features are suitable for high-frequency, high-speed read and write business.

      • Rdb:
        RDB persistence to generate point-in-time snapshots of data within a specified time interval

      • To create a new Rdb file:
        When you execute the Save command or the Bgsave command to create a new Rdb file, the program checks the keys in the database and the expired keys are not saved in the newly created RDB file.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Redis Topic Two: RDB and AOF persistence

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.