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

What is the difference between AOF and RDB in Redis

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

In this issue, the editor will bring you about the difference between AOF and RDB in Redis. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.

There are two Redis data storage modes: cache-only and persistence.

If you want Redis to be used only as a pure memory cache, you can use cache-only mode. For persistence persistent storage, Redis provides two persistence methods: RDB and AOF. With RDB or AOF, the data in Redis memory can be persisted to disk, and then the data can be backed up to another place, such as a cloud server.

RDB mode

The Redis main process fork a child process (?) that performs disk IO operations for persistence. RDB writes the data to a temporary file, and after the persistence ends, it replaces the last persisted file with this temporary file, which represents the data of redis at a certain time. However, RDB is persisted at intervals. If redis fails during persistence, data will be lost during this period of time (the biggest disadvantage of RDB is that it is not suitable to be the first priority recovery program. If you rely on RDB as the first priority recovery plan, you will lose more data).

Why a child process?

It is mainly due to the performance of Redis.

The Redis RDB persistence mechanism blocks the main process so that it cannot respond to client requests.

The working model of Redis responding to client requests is single-process and single-threaded. If you start a thread within the main process, it will create a race condition for data, in order to avoid the use of locks to degrade performance. Based on the above two points, this is why Redis executes RDB by starting a process.

AOF mode

You can simply think of AOF as a log file, which will only record the "change operation" (e.g. set/del, etc.) and append the "operation + data" in the form of formatting instructions (append, write disk sequentially, without any disk addressing overhead, so it is very efficient) to the end of the operation log file (usually set once per second), after the append operation returns (has been written to the file or is about to be written) To make actual data changes. " The "log file" saves all the operations in history; when server needs data recovery, you can directly replay the log file to restore all operations.

However, AOF files are larger and slower to recover than RDB files.

If the AOF file is too large, you can use the BGREWRITEAOF command (BGrewriteAOF) to optimize the aof file

The above is the difference between AOF and RDB in Redis shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

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

Internet Technology

Wechat

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

12
Report