In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
What are the ways in which redis persists data? I believe that many people's understanding of redis persistence data is in a state of limited knowledge. The editor summarizes the following. The following information is about redis persistence data.
Redis is called an in-memory database because it stores all its data in memory, so Redis has strong speed performance, but also because the data is stored in memory, when Redis restarts, all data stored in memory will be lost. To make data persistent, Redis provides two ways: RDB mode and AOF mode.
I. RDB mode
RDB persistence is accomplished through snapshotting. When certain conditions are met, Redis will automatically generate a copy of all the data in memory and store it on the hard disk. This process is called "snapshot". "snapshot" is similar to taking a picture and pressing the shutter. The moment the picture is fixed, it is called "snapshot".
There are four situations in which Redis takes a snapshot of data:
Take automatic snapshots according to configuration rules
The user executes the SAVE or BGSAVE command
Execute the FLUSHALL command
When performing replication (replication).
II. AOF mode
Persistence is achieved through RDB, and once the Redis exits abnormally, all data changed since the last snapshot will be lost. In order to reduce the risk of data loss caused by process termination, AOF can be used to achieve data persistence.
AOF persistence records every write and delete operation processed by the server in the form of a log. Query operations are not recorded, but are recorded in text. Detailed operation records can be seen in the file.
She appears to make up for the lack of RDB (data inconsistency), so it records each write in the form of a log and appends it to the file. The Redis restart will execute the write instruction from front to back according to the contents of the log file to complete the data recovery.
By default, Redis does not enable persistence in AOF mode. You can start it with the parameter appendonly: appendonly yes
When AOF persistence is turned on, every time a command that changes the data in Redis is executed, Redis will write the command to the AOF file on the hard disk, that is, the .aof format file stores some redis instructions.
At this time, it should be noted that when you frequently manipulate the data in Redis, the AOF format files will take up more and more memory, and there will be a lot of useless instructions, such as the continuous execution of set foo 1 dint set foo 2 Die set foo 3.
Then the first two instructions are meaningless, Redis is very powerful, it will automatically delete meaningless instructions, that is, whenever a certain condition is met, Redis will automatically rewrite the AOF file, and this condition can be set in the configuration file. The rewriting process is only related to in-memory data and has nothing to do with previous AOF files, which is similar to RDB.
When synchronizing hard disk data, due to the cache mechanism of the operating system, the data is not really written to the hard disk, but into the hard disk cache of the system. By default, the system performs a synchronization operation every 30 seconds, during which if the system exits abnormally, it will result in data loss in the hard disk memory.
Redis allows both RDB and AOF to be enabled, which not only ensures data security, but also makes backup operation very easy. AOF can effectively reduce the possibility of data loss, and RDB can make data backup easy to achieve.
After reading the above, do you have a general idea of how redis persists data? If you want to know more about the content of the article, welcome to follow the industry information channel, thank you for reading!
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.