In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Redis persistence in the use of RDB, in view of this problem, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Overview of Redis persistence
Redis persistence is divided into three ways: RDB (Redis DataBase), AOF (Append Only File) and AOF+RDB mixed persistence.
There are some things to say about Redis persistence:
1:RDB generates snapshots of Redis data at different points in time and stores them on disk.
2:AOF is only allowed to append files that are not allowed to be overwritten. It records all the write instructions executed by Redis. When Redis restarts next time, as long as you repeat these write instructions from front to back, you can achieve data recovery.
3: the hybrid method is to first use RDB for snapshot storage, and then use AOF persistence to record all write operations
Both 4:RDB and AOF can be used at the same time. In this case, if Redis is restarted, AOF will be preferred for data recovery. This is because the data recovery in AOF is more complete.
5: you can turn off RDB and AOF, so that Redis will become a pure memory database, just like Memcache
6: you can turn on the AOF function by configuring appendonly in redis.conf to yes
7: hybrid mode can be turned on through the aof-use-rdb-preamble configuration item
Overview of RDB mode
In RDB mode, Redis will create (fork) a child process for persistence. It will first write the data to a temporary file, and then replace the last persisted file with this temporary file after the persistence process is over. Throughout the process, the main process does not perform any IO operations, which ensures extremely high performance
If large-scale data recovery is needed and is not very sensitive to the integrity of data recovery, then RDB is more efficient than AOF. The disadvantage of RDB is that the data may be lost after the last persistence.
Configuration of RDB
1:save *: the frequency at which snapshots are saved. The first indicates how long it takes, in seconds, and the second * indicates at least the number of writes performed. When at least a certain number of writes are performed within a certain period of time, snapshots are saved automatically. Multiple conditions can be set.
(1) if you want to disable the RDB persistence policy, you can either set no save directive or pass an empty string parameter to save.
(2) if the RDB snapshot feature is enabled by the user, if Redis fails to persist data to disk, by default, Redis will stop accepting all write requests. The advantage of this is that it makes it clear to the user that the data in memory is inconsistent with the data on disk. If the next RDB persistence is successful, redis will automatically resume accepting write requests.
2:dbfilename: data snapshot file name (file name only, not directory), default dump.rdb
3:dir: the directory where the data snapshot is saved (this is the directory). The default is the current path.
4:stop-writes-on-bgsave-error: if configured as no, it means that you don't care about data inconsistencies or other means of discovering and controlling such inconsistencies, then you can also ensure that redis continues to accept new write requests when snapshot writes fail.
5:rdbcompression: for snapshots stored on disk, you can set whether to compress or not. If so, redis uses the LZF algorithm for compression. If you do not want to consume CPU for compression, you can set this feature to disable.
6:rdbchecksum: after storing the snapshot, you can also have redis use the CRC64 algorithm for data validation, but doing so will increase the performance consumption by about 10%. If you want to get the maximum performance improvement, you can turn this feature off.
7:rdb-del-sync-files: enabled to delete RDB files used in replication without persistence. This option is disabled by default.
The advantages of RDB are suitable for the problems of cold backup, high performance and fast data recovery RDB.
When you 1:fork a process, the data in memory is also copied, that is, the memory is twice as large as before.
2: each snapshot persistence is a complete write of memory data to disk, not incremental synchronous dirty data. If there is a large amount of data and a lot of write operations, it will inevitably cause a large number of disk io operations, which may seriously affect performance.
3: since snapshots are done at regular intervals, if redis accidentally down, all modifications since the last snapshot will be lost.
Trigger snapshot 1: automatic snapshot according to configuration rules 2: user executes save or bgsave commands 3: execute flushall commands 4: execute save commands when replicating replication
When the Save command is executed, Redis blocks all client requests and then performs snapshot operations synchronously.
Bgsave command
When you execute the bgsave command, Redis performs snapshot operations asynchronously in the background, and snapshots can also respond to client requests. The time of the last successful snapshot can be obtained through the lastsave command.
Flushall command
This command causes Redis to clear all data in memory. If the conditions for automatic snapshots are defined, a snapshot operation will be performed regardless of whether the conditions are met or not. If no conditions are defined for automatic snapshots, snapshots will not be taken.
This is the answer to the question about the use of RDB in Redis persistence. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about 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.