How Redis --- redis persistence

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/weixin_39207535/article/details/80209384

First posted a link:

https://www.cnblogs.com/mdxdjh/articles/6853109.html paper learn more article


There Speaking earlier, redis memory database used is stored in the form of key-value, due Redis data are stored in memory, if not configured persistence, after the restart redis data on the whole is lost, so the need to open the persistence of redis feature to save data to disk, when redis restart, you can restore data from disk. redis offers two ways to persist, one is RDB persistence, the other is AOF persistence ( the append only File)

    RDB

The principle is the Reids database records in memory timing to dump on disk RDB lasting .

RDB persistence means that within a specified time interval memory snapshot of the data set is written to disk, the actual operation is fork a child process, the first set of data written to a temporary file, write successfully, and then replace the file before , binary compressed storage.

AOF

The principle is the Reids operation log to additional write to files . AOF persisted in the form of log records processed by the server for each write, delete, query operation is not recorded , the recorded text, you can open the file to see the detailed operating record.

Advantages and disadvantages of the two methods

What are the advantages RDB exist?

1) Once this manner, then your entire Redis database will contain only one file, which for file backup is perfect. For example, you might intend to archive every hour last 24 hours of data, but also archived once in the last 30 days of data every day. With this backup strategy, once the system has failed catastrophically, we can very easily be restored.

2) For disaster recovery purposes, RDB is a very good choice. Because we can very easily be a separate file compression and then transferred to other storage media.

3) The performance is maximized. For service of process Redis, at the beginning of persistence, it is the only need to do is fork out the child, and then after the completion of these persistent work by the child, so that you can greatly avoid the process of an IO operation of the service.

4) Compared to the AOF mechanism, if the data set is large, start RDB efficiency will be higher.

RDB and what weaknesses exist?

1) If you want to guarantee high availability of data, that is, the maximum to avoid loss of data, then the RDB would not be a good choice. Because once the system downtime phenomenon before the timing of persistence, had not had time to write data on the disk will be lost.

2) Since the RDB through the fork a child process to assist with data persistence work, so if and when the data set is large, it may cause the entire server to stop serving hundreds of milliseconds, or even one second.

AOF advantage, what does?

1). This mechanism can result in higher data security, namely data persistence. Redis provides 3 in synchronization strategy, that sync every second, every modification and synchronization are not synchronized. In fact, asynchronous synchronization is complete per second, its efficiency is very high, the difference is that once the system downtime phenomenon, then within seconds the modified data will be lost. And every modify the synchronization, we can be regarded as synchronization persistence that occurs every time data changes will be immediately recorded to disk. It is foreseeable that in this way is the lowest in efficiency. As for non-synchronous, needless to say, I think we can correct understanding of it.

2). Since the mechanism writes to the log file append mode is used, even if the phenomenon of downtime during the writing process, without disturbing the contents of the log file already exists. However, if we write this operation is only half the data appeared system crash, do not worry, before the next startup Redis, we can to help us solve the problem of data consistency by redis-check-aof tool.

3) If the log is too large, Redis can automatically enable rewrite mechanism. That Redis to append mode will keep the modified data is written to the old disk file, while Redis also creates a new file to record what has changed on command is executed during this period. Therefore, when switching is performed rewrite data security can be guaranteed better.

4). AOF format comprising a clear, comprehensible log file for recording all the changes. In fact, we can complete the reconstruction data through the file.

AOF disadvantages, what does?

1) For the same number of data sets, AOF is generally larger than RDB document file. RDB speed when recovering large data sets faster than the speed of recovery of AOF.

2). Depending on the synchronization policy, AOF on the operating efficiency tends to be slower than in RDB. In short, the efficiency of synchronous per second strategy is relatively high, disable synchronization efficiency and RDB policy as efficient.

Both the selection criteria, is to see the system is willing to sacrifice some performance in exchange for higher cache coherency ( when aof), was willing to write frequent operation, do not enable the backup in exchange for higher performance, time to be run manually save the , do a backup (rdb). This is even more rdb some eventually consistent mean.

 
In fact, redis on persistent support is not very good, which is the disadvantage of non-relational database.

Guess you like

Origin blog.csdn.net/weixin_39207535/article/details/80209384