Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Workflow of AOF persistence mode in Redis

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Redis's RDB approach can't be persistent, but AOF can do it. If the data is important and the loss will have serious consequences, then the RDB approach is obviously not appropriate, and the AOF approach should be used. Aof is similar to mysql's binlog log, which only records new, modified and deleted operations. The difference is that redis will rewrite the aof file every once in a while to reduce the size of the aof file.

AOF workflow

Here, why the command should be written to aof_buf first, because if you write directly to the aof file, then the performance depends entirely on the io performance of the hard disk. Aof_buf is written to improve the performance of writes.

Configuration

Appendonly: whether to enable aof persistence. Default is no. If you want to open it, change it to yes.

Dir:aof file storage directory

Appendfilename:aof file name

Appendfsync:aof synchronization method. There are three values, which are as follows:

Always: synchronizes every time a command is written, with the highest data security but poor performance

Everysec: synchronization per second, default mode, high performance and security

No: synchronous operation is handed over to the operating system, and the security of the data is the worst.

The two configurations of auto-aof-rewrite-percentage and auto-aof-rewrite-min-size are related to the aof rewriting mechanism, and only if these two conditions are met at the same time will the rewriting mechanism be triggered.

Auto-aof-rewrite-min-size means that when overridden, the file size must be large. The default value is 64mb.

Auto-aof-rewrite-percentage indicates that the current file size is so much larger than the file size since the last rewrite.

AOF rewriting

The aof rewriting mechanism of redis has two ways: manual trigger and automatic trigger. The bgrewriteof command is entered when triggered manually. Automatic trigger satisfies all the above two conditions.

There are several situations why rewriting can reduce the size of a file:

Expired keys and deleted keys will no longer be recorded

Many individual operations can be done with a single operation, such as lpush a, lpush b, and lpush a b after rewriting.

Let's take a look at the aof rewriting process

Execute the bgrewriteof command

The main process fork gives a child process

The original aof mechanism continues to run, while new commands are written to aof_rewrite_buf

The child process generates a new aof file

Notify the parent process that the new aof file has been generated successfully; append the commands in aof_rewrite_buf to the new aof file; and replace the old aof file with the new aof file.

After completing the above steps, the aof rewrite is complete.

Note that if there are multiple redis services on a server, it is best to separate their rewriting times to prevent excessive competition between io and cpu.

These are the details of the AOF way of Redis persistence, please pay attention to other related articles!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report