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 Redis persistent storage mechanism?

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

Share

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

This article mainly explains "what is the Redis persistent storage mechanism". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what the Redis persistent storage mechanism is.

The data of Redis is all in memory, and if there is a sudden downtime, all data will be lost, so there must be a mechanism to ensure that the data of Redis will not be lost due to failure. This mechanism is the persistence mechanism of Redis.

1. RBD (snapshot)

Principle

At some point, the data in memory is written to a temporary file on disk, and after the persistence is over, the last persisted file is replaced with this temporary file.

Configuration file

Save 9001 # if the key value is modified once in 900s, snapshot save 30010 # if the key value is modified 10 times in 300s, snapshot save 60 10000 # Snapshot stop-writes-on-bgsave-error yes # background backup error occurs if the key value is modified 10000 times in 60 seconds Do you want to disable new writes? If you do not prohibit whether the rdb file exported by rdbcompression yes # easily causes data inconsistency, whether the rdb file exported by rdbchecksum yes # is compressed, whether the rdb file is imported during recovery to verify the integrity, whether the version is consistent, the storage path of the rdb file name dir / var/lib/redis # rdb derived from dbfilename dump.rdb #, AOF

Principle

‎ records the write operation ‎‎ command ‎‎ sent to the server to form an AOF file, which can only be appended but not modified. When Redis starts, it will read the AOF file and reconstruct the data (execute it again). The default name of the file is appendonly.aof ‎

Configuration file

Appendonly no # whether to enable the aof function appendfilename "appendonly.aof" # File name appendfsync always # synchronize to the buffer as soon as it is modified, and synchronize to disk appendfsync everysec # synchronize data to the buffer every second and synchronize to disk appendfsync no # redis does not set synchronization policy The parameters set by the kernel determine whether to synchronize the no-appendfsync-on-rewrite no # appendfsync if set to always or everysec, and whether to synchronize the disk auto-aof-rewrite-percentage 100. how often do you reconstruct the aof file, and what is the minimum size of the auto-aof-rewrite-min-size 64mb # aof file to reconstruct the aof file? Complete the crash repair automatically with the previous one using aof-load-truncated yes #

Aof rewriting, reconstruction

Merge a large number of repetitive commands into a single command without having to re-execute each command frequently.

III. AOF vs. RDB

AOF is more secure and can instantly synchronize data to a file, but it consumes disk Icano and is inefficient.

Snapshot is more efficient, and it is the best means of data synchronization for servers under normal operating conditions. It has the advantages of small file size, high efficiency and low security.

Note: RDB and AOF are enabled at the same time. AOF is used by default to recover data.

IV. Common architectures

In a well-structured environment: Master uses AOF,Slave and snapshot. The reason is that the main reason is to ensure that the data is complete and fast. ‎

Poor network environment: it is recommended to use master and slave at the same time to use AOF for more security

Network is good and requires intensive write operations: it is recommended that Master adopt snapshot,Slave and AOF

Thank you for reading, the above is the content of "what is the Redis persistent storage mechanism". After the study of this article, I believe you have a deeper understanding of what the Redis persistent storage mechanism is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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