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 are the persistence schemes in redis

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you "what are the persistence solutions in redis", which are easy to understand and clear, and hope to help you solve your doubts. Let me lead you to study and learn this article "what are the persistence solutions in redis".

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

There are two kinds of redis persistence schemes: RDB and AOF.

RDB

RDB persistence can be performed manually or periodically according to configuration. Its function is to save the database state at a certain point in time to a RDB file. RDB file is a compressed binary file, through which you can restore the state of the database at a certain time. Because the RDB file is saved on the hard disk, even if the redis crashes or exits, you can use it to restore the state of the restored database as long as the RDB file exists.

You can generate RDB files through SAVE or BGSAVE.

The SAVE command blocks the redis process until the RDB file is generated, and redis cannot process any command requests during the process blocking, which is obviously inappropriate.

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

AOF

Unlike RDB, AOF records the state of the database by saving write commands executed by the redis server.

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

When AOF persistence is active and the server finishes executing the write command, the write command will be appended to the end of the aof_buf buffer by append

Before the server ends each event loop, the flushAppendOnlyFile function is called to decide whether to save the contents of the aof_buf to the AOF file, which can be determined by configuring appendfsync.

Always # # aof_buf content is written and synchronized to the AOF file everysec # # writes the contents of the aof_buf to the AOF file. If the time of the last synchronization of the AOF file is now more than 1 second, the AOF file is synchronized again. No # # writes the aof_buf content to the AOF file, but the AOF file is not synchronized. The synchronization time is determined by the operating system.

If not set, the default option will be everysec, because although always is the safest (write commands for only one event loop will be lost), the performance is poor, while everysec mode may only lose 1 second of data, while no mode is as efficient as everysec, but will lose all write command data since the last time the AOF file was synchronized.

These are all the contents of the article "what are the persistence schemes in redis?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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

Development

Wechat

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

12
Report