Redis persistence RDB and AOF advantages and disadvantages and drawbacks

Redis is an advanced key-value database. Data can be persistent, and supported data types is very rich. There are strings, lists, sets, and ordered set. Calculating a set of support and on the server side, and cross-complement (-difference), etc., but also supports a variety of sorting. Therefore Redis may be viewed as a data structure of a server.

Redis interests of efficiency, the data cached in memory , Redis will periodically update the data written to disk or to modify the operation of writing the log file append, to ensure data persistence .

Redis is a persistent memory database support, data in memory can be synchronized to ensure persistent disk.

Redis persistence strategy : two kinds

  • RDB : Snapshots is a direct form of saving data to a memory dump file, time saving, save the policy.
  • AOF of : all the commands for editing the Redis server are saved to a file, a set of commands.

The default mode Redis is persistent snapshot of RDB

When Redis restarted, it will give priority to the use of AOF file to restore the data set because of AOF save file data sets are usually more complete than RDB files saved data set. You can even turn off the persistence function, so that only the data stored in the server is running.

RDB endurance of

Redis will default in the form of "RDB" a snapshot of the data persisted to disk, a binary file, dump.rdb

Works brief : When Redis persistence needs to be done, Redis will fork a child process, the child process writes the data to a temporary file on disk RDB. After the completion of the process to write temporary files, replace the original RDB, this advantage is that you can copy-on-write.

Redis default mode is persistent snapshot of RDB, the data in memory in a manner snapshot written to the binary file, the default file name is dump.rdb. Of course, we can also perform save or bgsave (asynchronous) do manual snapshots.

Redis.conf Configuration  : The default configuration is as follows

save 900 1 
save 300 10 save 60 10000 
  • 900 seconds, if more than one key to be modified, saved snapshot is initiated;
  • 300 seconds, if more than 10 key is modified, initiating a snapshot saved;
  • 1 minute, if 10000 key is modified, initiating a snapshot saved;

RDB advantages:

This file is ideally suited for backup: For example, you can in the last 24 hours, hourly backups RDB file, and each day of each month, and a backup RDB file. In this case, even when we have problems, you can always restore the data set to a different version. RDB is ideal for disaster recovery (disaster recovery).

RDB disadvantages:

If you need to try to avoid losing data in the event of server failure , then the RDB is not for you . Although Redis allows you to set various save points (save point) to control the frequency of RDB save the file, however, because RDB files need to save the state of the entire data set, so it is not an easy operation. So you may save time for at least 5 minutes before RDB file. In this case,  once the downtime occurs, you may lose a few minutes of data .

AOF persistence

Use AOF do persist, every write commands are added to the appendonly.aof through the write function, configuration: Start AOF persistent way

Redis.conf Configuration

appendfsync yes   
appendfsync always     #每次有数据修改发生时都会写入AOF文件。
appendfsync everysec   #每秒钟同步一次,该策略为AOF的缺省策略。

AOF can achieve full persistence, you only need to open the configuration file (default is no), then open the AOF appendonly yes, Redis each perform a data modification command will add it to the AOF file, restart when Redis , will read the file AOF "replay" to restore to the last moment before the Redis closed.

AOF advantage

AOF use Redis persistence will become very durable (much more durable): You can set different fsync strategies , such as no fsync, fsync once per second, or every fsync write command execution. AOF default policy for fsync once per second , in this configuration, Redis can still maintain good performance, and even if downtime occurs, it will only lose one second of data (fsync will be performed in the background thread, the main thread can continue its efforts to deal with command requests).

AOF shortcomings

For the same data sets, files generally AOF volume greater than the volume RDB file. According to fsync strategy being used, AOF speed may be slower than RDBIn general, fsync per second performance is still very high , and close fsync allows AOF speed and RDB as fast, even under high loads. But when dealing with a huge write load, RDB can provide the maximum delay time (latency) is more assured.

The difference between the two

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 persisted in the form of log records processed by the server every write, delete, query operation is not recorded, the recorded text, you can open the file to see the detailed operating record.

RDB and AOF, I should have a use which?

  • If you are very concerned about your data, but you can still withstand the loss of data within a few minutes, then you can just use RDB lasting.
  • AOF will be executed each command Redis added to the disk, the process will reduce the huge write performance Redis, do not know whether you can accept.

Database backup and disaster recovery : RDB timing generation snapshot (Snapshot) is very easy database backup, and restore the data set of RDB speed faster than the speed of recovery AOF.

Redis supports open simultaneously RDB and AOF, after a system reboot, Redis will give priority to the use of AOF to recover data, such data will be lost at least.

Original Address: https://www.cnblogs.com/shihaiming/p/9413596.html

Disclaimer: This article is only used as his study and, if offended, then deleted

 

Guess you like

Origin www.cnblogs.com/420ITboy/p/12309449.html