Redis Learning 03: Redis data persistence

Redis Learning 03: Redis data persistence

 

Redis data persistence

  Official website: https://redis.io/topics/persistence

 

 

   Induction that is divided RDB and AOF

 

RDB Introduction

  1- official website: https://redis.io/topics/persistence

 

   2-RDB: within a specified time interval, a snapshot of data written to the disk memory; Snapshot is a snapshot of jargon, it is restored to the snapshot file read directly into memory . Redis will create a separate ( fork ) a child process to persist, will be written to a temporary file in the data first, to be persistent processes are over, replaced by the last good persistence file with the temporary file. Throughout the process, the main process is not carried out any IO operations, which ensures a high performance, large-scale data recovery if needed, and not very sensitive to the integrity of the data recovery, then RDB way than the way AOF more efficient. RDB drawback is that after the last data persistence may be lost.

   3-Fork: Fork role is a copy of the same process with the current process. All processes of the new process (variables, environment variables, program counter, etc.) consistent with the original value drank process, but hi a new process, and as a child process of the original process fun.

   4-dump.rdb file: dump.rdb RDB is the default persistent file name can be configured in redis.conf

   5-RDB arrangement position: the configuration in redis.conf

   6- How to trigger a snapshot of RDB

    Method 1: default snapshot profile configuration: for example, set in the configuration file save 300 10, it means that if there is a change of at least 10 key 300 seconds, the persistent data file to dump.rdb

    Method 2: Using the save command or bgsave: wherein just saved when the save, regardless of the other, all the occlusion; bgsave time, the background Redis asynchronous snapshot operation, but also can respond to client requests.

    Method 3: Use flushall command: will produce dump.rdb, but it was empty, there is no meaning; the same time, shutdown can also be triggered snapshots

  7- How to restore: the backup file (dump.rdb) move to redis installation directory, and start the service (config get dir command to obtain directory)

  8-RDB advantages: suitable for large-scale data and data integrity and consistency less demanding recovery;

  9-RDB disadvantage: do a backup at certain intervals, so if redis accidentally fall down, you will lose all changes after the last snapshot. Fork, the memory data is a clone, approximately 2-fold expansion need to be considered

  10- How to Stop RDB: RDB dynamic stop saving rules: redis-cli config set save ''

AOF Introduction

  1- official website: https://redis.io/topics/persistence

 

  2-AOF: to form a log record for each write operation; Redis executed all the write command recorded (read operation is not recorded), but not the additional file can only overwrite the file, the beginning of the change starts, it reads Redis file rebuild the data, in other words, Redis, then restart it based on the contents of the log file will be written instruction execution from front to back once to play into the data returned to work;

  Saved 3-AOF is appendonly.aof file

  4- profile location

 

 

 

  5-AOF start / repair / recovery

    1- Start: Set appendonly redis.conf to yes in the configuration file, then restart redis can;

    2- normal recovery: Restart redis is automatically reloaded

    3- abnormal repair: first backup was written bad AOF file, then Linux command line redis-check-aof -fix appendonly.aof; final restart to redeis

  6-AOF Rewrite

  7-AOF advantage

    Each 1- modify synchronization: appendfsync always; synchronizes its persistent, but poor performance better data integrity

    2- second synchronization: appendfsync everysec; asynchronous operation, the second record, if one second downtime, loss of data

    3- sync: appendfsync no unsynchronized

  8-AOF disadvantage

    1- data of the same data set in terms of AOF document file is much larger than RDB, RDB slower than the speed of recovery

    2-AOF slower than RDB operating efficiency, better synchronization strategy efficiency per second, the same is not synchronized efficiency and RDB

to sum up

  • Redis is enabled by default RDB persistent way, within a specified time interval, to perform a specified number of write operations, the data will be written to memory to the disk.
  • RDB persistence for large-scale data recovery but its poor data integrity and consistency.
  • Redis need to manually open the AOF persistent mode, the default is second to write the log file is appended to the AOF.
  • AOF data integrity than RDB high, but much recorded content will affect the efficiency of data recovery.
  • Redis for large AOF document problems and provide weight-loss mechanism rewritten.
  • If only intend to use caching Redis, you can turn off persistence.
  • If you plan to use Redis persistence. RDB recommendations and AOF are open. In fact, RDB is more suitable for data backup, leave a way of escape. AOF a problem, as well as RDB.

 

Guess you like

Origin www.cnblogs.com/wobuchifanqie/p/11736955.html