Advanced Redis: Redis persistence mechanism of

Advanced Redis: Redis persistence mechanism of

Redis persistence mechanism currently include RBD and AOF in two ways.

RDB persistence

RDB persistent approach is a snapshot of the data stored in the specified time interval. Expired keys are not stored in a snapshot. If you restore the data has expired, will be deleted by active or passive cleanup strategy.

  • Pros: Performance is small, fast recovery speed. Compared with the AOF, in reply to a large amount of data, faster.
  • Drawback: save is blocking the snapshot is created, if the data of the General Assembly affecting other responses for the command. In the case of failure or forced to close , there will be data loss.
//创建子线程异步将快照写入磁盘
bgsave 
//阻塞式存储快照,执行该命令时,不在响应其他指令
save  

// Redis.Config 可以对save配置进行调整。两个条件满足一个都会触发生成快照。
save 900 1 //900S内 至少1次写操作 触发 快照
save 300 10 //300S内 至少10次写操作 触发 快照
save 60 10000 //60S内 至少10000次写操作 触发 快照      

AOF persistence

Record each server write operations. Will re-execute the command to restart the server to recover the data. AOF command to save an additional protocol redis each write operation to the end of the file. Redis also on the AOF files for background rewritten, so that the volume will not AOF file is too large.

  • Pros: Security disaster recovery backup file can be modified to read.
  • Disadvantages: backup files take up a large space, the recovery is slower than the RDB.

  • Open: appendonly changes in property values ​​redis.config to yes, the default is no.
  • AOF strategy adjustment

  //每次修改都写入AOF 绝对不丢失数据。最安全
  appendfsync always 
  //每秒写入一次AOF 默认策略  在周期内同样存在丢失数据的情况。
  appendfsync everysec
  //关闭AOF持久化 性能最好
  appendfsync no

How to choose the way of persistence

  • If you want to achieve data security PostgreSQL, we recommend two ways simultaneously.
  • If you can withstand a certain time within (a few minutes or a few seconds), you can only use RDB snapshots.
  • Many users only use AOF way, but the official is not recommended , because there will be a snapshot timing generation data management, while the AOF presence BRPOPLPUSH BUG in a particular case, because RDB is created from scratch, in theory, be more robust.

note

Although Redis provides a snapshot of RDB and persistent AOF two kinds of ways, but both methods have their advantages and disadvantages:

  • RDB can not guarantee that data is not lost completely, partial data loss will exist, the specific number of missing data, depending on the size and volume of business data Redis configuration file on the trigger mechanism RDB configuration.
  • AOF will also use the presence of the data loss, and in particular the relevant period appendfsync configuration, while the AOF will reduce the read and write performance Redis, and can not support a large amount of data.

Above is related presentations Redis persistence in operation, the more other instructions can refer to the official website, Redis official website , Thanks for reading, I hope for your help.

Guess you like

Origin www.cnblogs.com/enjoyitlife/p/11963052.html