In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "summary of Redis backup methods". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "summary of Redis backup methods"!
First, there are two ways to persist redis:
RDB: take a snapshot of the database state in memory
AOF: write every write command to a file
RDB mode: save the database state of redis in memory to disk. RDB file is a compressed binary file, through which the data state of RDB file can be restored.
How to generate RDB:
Point to the command to generate manually
Automatic generation through configuration
1. Point to the command to generate manually
There are two redis commands that can generate RDB files, one is SAVE, and the other is that the BGSAVE,SAVE command blocks the redis server process until the RDB file is created. During the server blocking, the server cannot handle any processes, BGSAVE will send a child process, and the child process will be responsible for creating the RDB. File, the server process (parent process) continues to process command requests, and before the creation of the RDB file ends, the BGSAVE and SAVE commands sent by the client will be rejected by the server.
two。 Automatically generated through configuration?
You can set the save option for the server configuration so that the server automatically executes the BGSAVE command at regular intervals, and multiple save conditions can be set through the save option, but the BGSAGE command will be executed as long as any of the conditions are met.
For example:
Save 900 1
Save 300 10
Save 60 10000
Then the BGSAVE command will be executed as long as one of the following three conditions is met
The server made one change to the database within 900 seconds
The server made 10 changes to the database within 300 seconds
The server made 10000 changes to the database in 60 seconds
AOF mode: it is an AOF file refresh method to record the database status by saving the write commands executed by the redis server. There are three ways:
1.appendfsync always-every time a modification command is submitted, fsync is called to the AOF file, which is very slow, but safe.
2.appendfsync everysec-call fsyns every second to refresh to the AOF file, quickly but may lose data within a second
3.appendfsync no-rely on OS for refresh. Redis does not actively refresh AOF, which is the fastest but with poor security.
Default and recommended refresh per second, so that both speed and security are achieved.
II. Data recovery
1.ROB mode
The loading of the ROB file is performed automatically when the server starts, and there is no command specifically for loading the ROB file, as long as the redis server is detected when it is restarted
When the ROB file exists, it automatically loads the ROB file and remains blocked during the server load until the load is complete.
2.AOF mode
When the server starts, it restores the data before the server shuts down by loading and executing the commands saved in the AOF file. The specific process is:
Load the AOF file
Create an impersonation client
Read a command from an AOF file
Execute commands using an impersonated client
Loop to read and execute the command until it is all complete
If AOF and ROB mode are started at the same time, AOF is preferred. Only AOF files are loaded at startup to recover data.
III. Comparative summary of RDB and AOF
1 、 RDB
The data is written to a temporary file at some point in time, and after the persistence is over, the last persisted file is replaced with this temporary file to achieve data recovery. The time point at which the execution data is written to the temporary file can be determined by configuration. By configuring redis, if more than m key are modified in n seconds, a RDB operation is performed. This operation is similar to saving all the data of a Redis at this point in time, a snapshot of the data. All of this persistence method is also commonly called snapshots.
2 、 AOF
Append-only file, append the "operation + data" to the tail of the operation log file in the way of formatting instructions, and then make the actual data change after the append operation returns (already written to the file or about to be written). The "log file" saves all the operation procedures in history; when server needs data recovery, you can directly replay the log file to restore all the operation procedures. AOF is relatively reliable, which is almost the same as txn-log in bin.log, apache.log and zookeeper in mysql. The contents of the AOF file are strings that are very easy to read and parse.
3. The choice of two backup schemes:
For RDB persistence
On the one hand, bgsave will block the redis main process when performing fork operations.
On the other hand, the child process will also bring IO pressure to write data to the hard disk, but the integrity and consistency of the data may be less affected by the backup conditions, while the AOF persistence due to the continuous writing IO pressure is greater, but the data consistency and integrity are better.
At this point, I believe you have a deeper understanding of the "summary of Redis backup methods", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.