Redis two persistence methods (RDB & amp; AOF) and redis two rdb

Source: Internet
Author: User

Redis two persistence methods (RDB & AOF) and redis two rdb

Crawlers and reposts please indicate the original address; blog garden snail: http://www.cnblogs.com/tdws/p/5754706.html

What if the memory required by Redis exceeds the available memory? How does Redis modify data multithreading concurrency-Redis concurrent lock basic operations of redis in windows and master-slave replication so that data backup and read/write separation Redis two persistence modes (RDB & AOF)

Redis does not require too many developers to participate in the persistence process. What should we do? In addition to in-depth understandingRDBAndAOFOfWorking PrincipleThe rest is to develop appropriate strategies based on the actual situation. It is more complicated, that isCustomizes a highly available and data security policy.

Let's take a look at the RDB persistence method:

In the RDB mode, you have two options. One is to manually execute the persistent data command to allow redis to take a data snapshot, the other is to automatically persist data when certain conditions of the policy are met according to the configuration file policy you configured. You still have two options to manually execute the persistence command:SaveCommands andBgsaveCommand.

SaveOperations work in the Redis main thread, soBlockingOther request operations should be avoided.

(By defaultDump. rdbFile, and automatically read the file after redis restarts. It is reported that, normally10 millionString type key,1 GBThe time when the snapshot file is synchronized to the memory is20-30 seconds)

BgSave calls Fork to generate sub-processes. The parent process continues to process requests. The sub-process writes data to a temporary file and replaces the original. rdb file after writing the data. When Fork occurs, the memory of the Parent and Child processes is shared. Therefore, in order not to affect the data snapshot of the child process, the modified data will be copied, instead of the shared memory. Therefore, the persistent data of RDB is the data when the Fork occurs. In this case, the persistent data will be lost for a period of time if it goes down in some cases. If your actual situation is not so sensitive to data loss, you can also retrieve or lose some of the data from the traditional database, so you can choose the RDB persistence mode.

Let's talk about the configuration file policy again. In fact, it works the same as the bgsave command for persistence.

This is the configuration fileDefault policy, The relationship between them is or, every900Seconds, at least changed during this periodOneKey value for snapshot. Or everyThree hundred seconds, ChangedTenThe key value is used as a snapshot. Or every60Seconds, changed at least10 thousandKey value (for example, snapshot.

Next we will talk about the AOF snapshot method:

AOF, append only file.

In the configuration file, modify appendonly to yes. After AOF persistence is enabled, every command you run will be recordedAppendonly. aofFile. But in fact, the command is not immediately written to the hard disk file, but to the hard disk cache. In the following policy, configure how long it will be written from the hard disk cache to the hard disk file. To a certain extent, there will still be data loss, but you can greatly reduce the data loss.

Here is the AOF persistence policy. Redis is used by default.EverysecThat is to say, it is persistent once per second, while always will be immediately written into the aof file every operation. WhileNoThe default synchronization operation is 30 s. Of courseAlwaysIt must be the least efficient, I thinkEverysecThis is enough, and the data security performance is high.

Redis also allows us to use two methods at the same time. After restarting redisAofTo restore data, becauseAofRatioRdbSmall data loss.

Differences and in-depth understanding:

RDBEach snapshot operation record all the information of the entire dataset. RDB is faster when data is restored, maximizing redis performance. Sub-processes have no performance impact on the parent process.

AOFThe command operations of redis are recorded in sequence. In case of accidents, data is rarely lost. He keeps adding operation log records to aof files. You may say how large such files are. Yes, it will indeed become huge, but redis will have an optimized strategy, for exampleKey1Key operation, set key1 001, set key1 002, set key1 003. The optimization result is to remove the first two. The specific optimization configuration in the configuration file corresponds

The former refers to the number of the size of the last aof rewrite aof file, which will be optimized again. If it has not been overwritten, it will be dominated at startup. The latter limits the minimum aof file size that can be overwritten.BgrewriteaofThe command is a manual rewrite command that will fork sub-processes and rebuild the database status in the temporary file without any impact on the original aof. After the old status is rebuilt, it will also append the data from a period of time after the fork occurs to the temporary file, and finally replace the original aof file. The new command will continue to append the data to the new aof file.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.