In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article is about the pros and cons of persistence in redis. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.
Redis is an advanced key-value database. It is similar to memcached, except that data can be persisted and supports a wide range of data types. There are strings, linked lists, sets and ordered collections. Support in the server-side calculation of the collection union, intersection and complement set (difference), etc., but also supports a variety of sorting functions. So Redis can also be seen as a data structure server.
All data in Redis is stored in memory and then saved to disk asynchronously from time to time (this is called "semi-persistent mode"); each data change can also be written to an append only file (aof) (this is called "full persistence mode").
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).
So what's the difference between these two persistence methods, and how to choose them?
RDB persistence means that the snapshot of the dataset in memory is written to disk within a specified time interval. The actual operation is a child process of fork, which first writes the dataset to a temporary file, and then replaces the previous file and stores it with binary compression.
AOF persistence records every write and delete operation processed by the server in the form of log, query operation is not recorded, it is recorded in the form of text, and you can open the file to see the detailed operation record.
Both advantages and disadvantages
What are the advantages of RDB?
1)。 Once you use this approach, your entire Redis database will contain only one file, which is perfect for file backup. For example, you might plan to archive data for the last 24 hours every hour, as well as data for the last 30 days once a day. Through this backup strategy, in the event of a catastrophic failure of the system, we can recover very easily.
2)。 RDB is a very good choice for disaster recovery. Because we can easily compress a single file and then transfer it to other storage media.
3)。 Maximize performance. For the Redis service process, at the beginning of persistence, the only thing it needs to do is to fork the child process, and then the child process completes the persistence work, which can greatly prevent the service process from performing IO operations.
4)。 Compared with the AOF mechanism, if the dataset is large, the RDB startup efficiency will be higher.
What are the disadvantages of RDB?
1)。 If you want to ensure high availability of data, that is, to avoid data loss as much as possible, then RDB will not be a good choice. Because once the system goes down before timing persistence, data that has not been written to disk before will be lost.
2)。 Because RDB assists in data persistence through the help child process, if the dataset is large, it may cause the entire server to go out of service for hundreds of milliseconds, or even 1 second.
What are the advantages of AOF?
1)。 This mechanism can bring higher data security, that is, data persistence. Three synchronization strategies are provided in Redis, that is, synchronization per second, synchronization per modification, and async. In fact, synchronization per second is also done asynchronously, and its efficiency is also very high. The only difference is that once the system downtime occurs, then the modified data within this second will be lost. Every time we modify synchronization, we can think of it as synchronous persistence, that is, every data change that occurs is immediately recorded to disk. It can be predicted that this approach is the least efficient. As for non-synchronization, needless to say, I think everyone can understand it correctly.
2)。 Because this mechanism uses append mode to write log files, even if there is a downtime in the writing process, it will not destroy the content that already exists in the log file. However, if we only write half the data this time and the system crashes, don't worry, we can use the redis-check-aof tool to help us solve the data consistency problem before the next startup of Redis.
3)。 If the log is too large, Redis can automatically enable the rewrite mechanism. That is, Redis constantly writes the modified data to the old disk file in append mode, and Redis also creates a new file to record which modification commands were executed during this period. Therefore, data security can be better guaranteed when rewrite switching is carried out.
4)。 AOF contains a clearly formatted, easy-to-understand log file for recording all changes. In fact, we can also complete the reconstruction of the data through this file.
What are the disadvantages of AOF?
1)。 For the same number of datasets, AOF files are usually larger than RDB files. RDB recovers large datasets faster than AOF does.
2)。 Depending on the synchronization strategy, AOF tends to be slower than RDB in terms of efficiency. In short, the efficiency of synchronization per second policy is relatively high, and the efficiency of synchronization disable policy is as efficient as that of RDB.
The standard of choice between the two is to see whether the system is willing to sacrifice some performance for higher cache consistency (aof), or is willing to write frequently, do not enable backup in exchange for higher performance, and then do backup (rdb) when save is run manually. Rdb is even more eventually consistent.
Thank you for reading! So much for sharing the advantages and disadvantages of persistence in redis. I hope the above content can be helpful to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.