[Redis Reading notes] Part two single-machine database RDB Persistence

Source: Internet
Author: User
Tags redis server

An RDB in memory is saved as a file for the RDB to persist. RDB file when a binary file is being opened.

One-load and storage

The file is loaded at server startup (Rdbload ()) because the AOF update frequency is higher than the RDB, so if the AOF persistence feature is turned on, the server will first restore the db from AoF, and only aof shut down to restore the database from the RDB.

The storage of the file is implemented by the Rdbsave ()/RDB.C, which can be triggered by the Save/bgsave command, which is processed directly by Redis server and cannot handle other commands, which start the child process for processing, while the server can process the other commands, but When the Bgsave executes, the Save command can no longer be executed, the execution of Bgsave is also not possible, and finally bgrewriteaof can not be executed at the same time and Bgsave.

Two-cycle storage

Save 900 1

Save 300 10

Save 60 10000

The above three commands represent one of the satisfying conditions that will trigger Bgsave:

1. At least 1 updates in 900 seconds

2. Update at least 10 times in 300 seconds

3. At least 10,000 updates in 60 seconds

These times and the number of updates are set, stored in

structSaveparam {//How many seconds?time_t seconds; //How many modifications occurred    intchanges;};structredisserver{ ...structSaveparam *saveparams;/*Save points Array for RDB*/
...
The number of times the database has been modified since last SAVE was executed
Long long dirty; /* Changes to DB from the last Save */

//Last time the SAVE was completed
time_t Lastsave; /* Unix time of last successful save */

...};

The above dirty, on behalf of the last successful save/bgsave, how many times the database has been updated. Lastsave records the last time the Save/bgsave was successfully executed.

The Servercron () function performs a 100ms cycle, with the values in Saveparams and the dirty and Lastsave comparisons, to update the processing of the RDB.

The file structure of the three RDB

The Rdb file is a binary file, format customization, there is not much to say, examples are as follows:

[Redis Reading notes] Part two single-machine database RDB 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.