Redis persistence of rdb, aof

Overview

Redis is an in-memory database. If the state of the database in memory is not saved to disk, once the server process exits, the state of the database in the server will also disappear. So Redis provides persistence function!

RDB ( Redis DataBase )

redis defaults to rdb

The snapshot of the data set in the memory is written to the disk within the specified time interval, that is, the Snapshot snapshot. When it is restored, it reads the snapshot file directly into the memory.

Redis will create (fork) a child process for persistence. It will first write the data to a temporary file (dump.rdb). After the persistence process is over, the temporary file will be used to replace the last persistence. Good file. During the whole process, the main process does not perform any IO operations. This ensures extremely high performance. If large-scale data recovery is required, and the integrity of data recovery is not very sensitive, the RDB method is more efficient than the AOF method. The disadvantage of RDB is that the data after the last persistence may be lost.

触发条件

1. When the save rules in the configuration file are met, the rdb rule will be triggered automatically.
2. Executing the fluxhall command will also trigger our rdb rule!
3. Exit redis and an RDB file will also be generated!

如何恢复rdb文件

Just put the rdb file in our redis startup directory. When redis starts, it will automatically check dump.rdb to restore the data!

优点:

1. Suitable for large-scale data recovery!
2. Low requirements for data integrity!

缺点∶

1. It takes a certain time interval for process operation! If redis crashes unexpectedly, the last modified data will be gone!
2. When the fork process, it will occupy a certain content space!!

AOF( Append Only File)

redis is not turned on by default

Record all our commands, and execute this file once when restoring!

Record each write operation in the form of a log, record all the instructions executed by Redis (read operations are not recorded), only append files but not rewrite files, redis will read the file to rebuild the data at the beginning of the startup. In other words, if redis restarts, it will execute the write command from front to back according to the contents of the log file to complete the data recovery work. If there is a problem with the restart log file, then redis cannot be started.

Aof saves the appendonly.aof file

优点:

Using AOF persistence will make Redis very durable (much more durable): you can set different fsync policies, such as no fsync, fsync once per second, or fsync every time a write command is executed. The default policy of AOF is fsync once per second. In this configuration, Redis can still maintain good performance, and even if a failure occurs, only one second of data will be lost (fsync will be executed in a background thread, so The main thread can continue to work hard to process command requests).

缺点:

Compared with data files, AOF is much larger than RDB, and the repair speed is also slower than RDB!
Aof's operating efficiency is also slower than RDB, so our default configuration for redis is RDB persistence!

Guess you like

Origin blog.csdn.net/AIJXB/article/details/113886584