In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "two persistence ways of redis sharing". In daily operation, I believe many people have doubts about the two persistence ways of redis sharing. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "two persistence ways of redis sharing"! Next, please follow the editor to study!
1. What persistence mechanisms does Redis provide:
1)。 RDB persistence:
This mechanism means that a snapshot of a dataset in memory is written to disk within a specified time interval.
2)。 AOF persistence:
This mechanism will record every write operation processed by the server in the form of log, and will read the file at the beginning of the Redis server startup to rebuild the database to ensure that the data in the database is complete after startup.
3)。 No persistence:
We can configure to disable the persistence of the Redis server so that we can think of Redis as an enhanced version of memcached.
4)。 Apply AOF and RDB at the same time.
Second, the advantages and disadvantages of RDB mechanism:
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.
Third, the advantages and disadvantages of AOF mechanism:
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.
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.
4. Other:
1. Snapshotting:
By default, Redis dump a snapshot of the dataset to the dump.rdb file. In addition, we can also modify the frequency of dump snapshots of the Redis server through the configuration file. After opening the 6379.conf file, we search save and see the following configuration information:
Save 9001 # after 900s (15 minutes), if at least one key changes, the dump memory snapshot.
Save 30010 # after 300 seconds (5 minutes), if at least 10 key changes, the dump memory snapshot.
Save 60 10000 # after 60 seconds (1 minute), if at least 10000 key changes, the dump memory snapshot.
2. The mechanism of Dump snapshots:
1)。 Redis forks the child process first.
2)。 The child process writes snapshot data to a temporary RDB file.
3)。 When the child process completes the data write operation, it replaces the old file with a temporary file.
3. AOF file:
As mentioned above, RDB's snapshot timing dump mechanism cannot guarantee good data persistence. If our application is really concerned about this, we can consider using the AOF mechanism in Redis. For the Redis server, the default mechanism is RDB, and if you need to use AOF, you need to modify the following entry in the configuration file:
Change appendonly no to appendonly yes
From now on, every time Redis receives a command for data modification, it will append it to the AOF file. The next time Redis restarts, you need to load the information in the AOF file to build the latest data into memory.
4. Configuration of AOF:
There are three synchronization methods in the configuration file of Redis, which are:
Appendfsync always # is written to the AOF file every time a data modification occurs.
Appendfsync everysec # synchronizes once per second, which is the default policy for AOF.
Appendfsync no # is never synchronized. Efficient but the data is not persisted.
5. How to repair corrupted AOF files:
1)。 Make an extra copy of the existing corrupted AOF file.
2)。 Execute the "redis-check-aof-- fix" command to repair the corrupted AOF file.
3)。 Restart the Redis server with the repaired AOF file.
6. Data backup of Redis:
In Redis, we can back up the running Redis data files online by copy. This is because once the RDB file is generated, it will not be modified. Redis dump the latest data into a temporary file each time, and then rename the temporary file to the original data file name using the atomicity of the rename function. So we can say that copy data files are secure and consistent at any time. In view of this, we can back up the data files of Redis regularly by creating cron job, and copy the backup files to the disk media.
At this point, the study of "two persistence ways of redis sharing" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.