Redis's RDB Persistence

Source: Internet
Author: User
Tags redis server

Redis is a key value to the database server, the server usually contains any non-empty database, and each non-empty database can also contain any key value pairs, for the sake of convenience, we have a non-empty database in the server and their key-value pairs are collectively referred to as the database state.

Because Redis is a memory database, it stores its own database state in memory, so if you do not try to save the database state stored in memory to disk, then once the server process exits, the database state in the server will disappear. To solve this problem, Redis provides the RDB persistence feature, which saves Redis in-memory database state to disk and avoids accidental data loss.

RDB persistence generates an RDB file that is a compressed binary that enables you to restore the state of the database when an RDB file is generated.

1. rdb File creation and onboarding

There are two Redis commands that can be used to generate an RDB file, one is save and the other is bgsave.

The Save command blocks the Redis server process until the Rdb file is created, and the server cannot process any command requests during server process blocking :

Redis> SAVE//wait until the Rdb file is created

Ok

Unlike the Save command, which directly blocks the server process, thebgsave command derives a child process, which is then responsible for creating the Rdb file, and the server process (the parent process) continues to process the command request :

Redis> BGSAVE//derive child processes and create RDB files from sub-processes

Background Saving started

Unlike using the Save command or the Bgsave command to create an RDB file, the onboarding of anrdb file is performed automatically when the server starts, and Redis does not have a command specifically for loading an RDB file. Whenever the Redis server detects that an RDB file exists at startup, it automatically loads the Rdb file . While the server is loading the Rdb file, it will remain blocked until the loading work is complete.

It is also worth mentioning that because the update frequency of the AoF file is usually higher than the update frequency of the Rdb file, therefore:

    • If the server turns on the AOF persistence feature, the server takes precedence over the aof file to restore the database state.
    • The server uses the Rdb file to restore the database state only when the AOF persistence feature is turned off.

2, automatic separation of the preservation

Because the Bgsave command can be executed without blocking the server process, Redis allows the user to automatically execute the bgsave command every time, by setting the Save option for the server configuration.

Users can set multiple save conditions through the Save option, but the server executes the Bgsave command whenever any of these conditions are met.

For example, if we provide the following configuration to the server:

Save 1 #900秒 1 changes

Save #300秒 10 Changes

Save 10000 #60秒 10,000 changes

So as long as any of the above three conditions are met, thebgsave command will be executed.

Redis's 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.