Home >Database >Redis >What are the persistence solutions in redis?

What are the persistence solutions in redis?

WBOY
WBOYforward
2023-05-27 08:08:02799browse

What are the persistence methods? What's the difference?

Redis persistence solutions are divided into two types: RDB and AOF.

RDB

RDB persistence can be executed manually or periodically according to the configuration. Its function is to save the database status at a certain point in time to an RDB file. The RDB file is a compressed A binary file through which the state of the database at a certain moment can be restored. Since the RDB file is saved on the hard disk, even if redis crashes or exits, as long as the RDB file exists, it can be used to restore the state of the database.

RDB files can be generated through SAVE or BGSAVE.

The SAVE command will block the redis process until the RDB file is generated. During the process blocking period, redis cannot process any command requests, which is obviously inappropriate.

BGSAVE will fork out a child process, and then the child process will be responsible for generating the RDB file. The parent process can continue to process command requests without blocking the process.

AOF

AOF is different from RDB. AOF records the database status by saving the write commands executed by the redis server.

AOF implements the persistence mechanism through three steps: append, write, and synchronize.

  1. When AOF persistence is activated, after the server executes the write command, the write command will be appended to the end of the aof_buf buffer

  2. Before each event loop ends in the server, the flushAppendOnlyFile function will be called to determine whether to save the contents of aof_buf to the AOF file. This can be determined by configuring appendfsync.

always ##aof_buf内容写入并同步到AOF文件
everysec ##将aof_buf中内容写入到AOF文件,如果上次同步AOF文件时间距离现在超过1秒,则再次对AOF文件进行同步
no ##将aof_buf内容写入AOF文件,但是并不对AOF文件进行同步,同步时间由操作系统决定

If not set, the default option will be everysec, because although always is the safest (only one event loop write command will be lost), the performance is poor, and everysec The mode may only lose 1 second of data, while the efficiency of the no mode is similar to everysec, but all write command data after the last synchronization of the AOF file will be lost.

The above is the detailed content of What are the persistence solutions in redis?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete