first, there are two ways of Redis persistence: 1.RDB: Snapshots of In-memory database state
2.AOF: Write every write command to the file, similar to the MySQL binlog log
RDB: Save the Redis in-memory database state to disk, RDB file is a
A compressed binary file that enables you to restore the state of the data that generated the Rdb file.
How the RDB is generated:
1. Point to command manual generation
There are two Redis commands that can generate RDB files, one is SAVE and the other is Bgsave,save
Command blocks the Redis server process, knowing that the Rdb file is created, and that during server blocking, the service
The service cannot handle any process, Bgsave sends a subprocess, and then the child process is responsible for creating the RDB
file, the server process (the parent process) continues processing the command request, creating the Rdb file before the end of the client
The Bgsave and SAVE commands sent are rejected by the server
2. Automatic Generation by configuration
You can set the Save option for the server configuration so that the server automatically executes the Bgsave command every once in a while, and you can set multiple save conditions with the Save option, but the bgsage command is executed whenever either of these conditions is met
Columns such as:
Save 900 1
Save 300 10
Save 60 10000
So long as one of the following three conditions is met, the Bgsave command is executed
The server changed the database 1 times within 900 seconds
The server changed the database 10 times within 300 seconds
The server changed the database 10,000 times within 900 seconds
AoF mode: is to record the state of the database AoF file Refresh method by saving Redis server's write command, there are three kinds:
1.appendfsync always-Fsync to aof file is invoked for each modification command, very slow but safe;
2.appendfsync everysec--calls Fsyns refresh to aof file every second, quickly but may lose data in one second;
3.appendfsync no--rely on the OS to refresh, Redis not active refresh aof, so the fastest but security is poor;
The default and recommended refresh per second, which is done in both speed and security
ii. Data Recovery 1.ROB mode
The load of Rob files is performed automatically when the server is started. Not specifically used to load the Rob File command, as long as the Redis server detects that Rob file exists when it is restarted, it will automatically load Rob's file, which will remain blocked during the server load, until the loading work is complete
2.AOF mode
When the server starts, it restores the data before the server is shut down by loading and executing commands saved in the AoF file, the specific library state process:
Loading aof files
To create a mock client
Read a command from the AoF file
To execute a command using an impersonation client
Loop read and execute command, know all complete
If the AOF and Rob methods are started at the same time, aof first, loading only the AoF file restore number when the home is in
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.