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

How to configure redis persistence

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

The editor in this issue will bring you a way to configure redis persistence, analyze and describe it from a professional point of view. I hope you can get something after reading this article.

Since the data of Redis is stored in memory, if persistence is not configured, all data will be lost after redis restart, so you need to enable the persistence feature of redis to save the data to disk. When redis restarts, you can recover the data from disk.

Redis provides two ways for persistence, one is RDB persistence (the principle is to dump the database records of Reids in memory regularly to RDB persistence on disk), and the other is AOF (append only file) persistence (the principle is to write the operation log of Reids to a file in an appended way).

RDB:RDB persistence is the process of generating a snapshot of the current process data and saving it to the hard disk. The process of triggering RDB persistence can be divided into manual trigger and automatic trigger.

Trigger mechanism

Manual triggers correspond to save and bgsave commands respectively

Save command: block the current Redis server until the RDB process is completed, which will cause long-term blocking for instances with large memory, which is not recommended online.

DB saved on disk

Bgseve command: the Redis process executes the fork operation to create the child process, and the RDB persistence process has the responsibility of the child process, which ends automatically after completion. Blocking occurs only in the fork phase, usually for a short time.

* Background saving started by pid 3151 * DB saved on disk* RDB: 0 MB of memory used by copy-on-write* Background saving terminated with success

Automatic trigger

Triggered in the following scenarios

1) use save-related configurations, such as "save m n". Indicates that bgsave is automatically triggered when there are n modifications to the dataset within m seconds.

2) if the slave node performs a full copy operation, the master node automatically executes bgsave to generate RDB files and sends them to the slave node.

3) when you execute the debug reload command to reload Redis, the save operation will also be triggered automatically.

4) when the shutdown command is executed by default, bgsave is automatically executed if the AOF persistence feature is not enabled.

AOF: each write command is recorded as an independent log, and the data is recovered by re-executing the command in the AOF file when restarting. Main function: to solve the real-time performance of data persistence.

Use AOF

To enable AOF, you need to set the configuration: appendonly yes, which is not enabled by default. The file name is set through the appendfilename configuration, and the default is appendonly.aof.

1) all write commands are appended to the aof_buf (buffer).

2) the AOF buffer synchronizes with the hard disk according to the corresponding policy.

3) as the AOF file becomes larger and larger, it is necessary to rewrite the AOF file regularly to achieve the purpose of compression.

4) when the Redis server is restarted, the AOF file can be loaded for data recovery.

The above is the way to configure redis persistence shared by the editor. If you have similar doubts, it will not hinder your understanding with reference to the above analysis. If you want to know more about it, please follow the industry information.

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