Redis的AOF持久化

1.append only file (AOF持久化)

本质:把用户执行的每个“写”指令(添加、修改、删除)都备份到文件中,还原数据的时候就是执行具体指令而已。

Redis的AOF持久化

开启AOF持久化(会清空redis内部的数据)

(同时可以修改备份文件的名字,默认是appendonly.aof)

[php] view plain copy
 print?
  1. # AOF and RDB persistence can be enabled at the same time without problems.  
  2. # If the AOF is enabled on startup Redis will load the AOF, that is the file  
  3. # with the better durability guarantees.  
  4. #  
  5. # Please check http://redis.io/topics/persistence for more information.  
  6.   
  7. appendonly yes  

配置文件被修改,需要删除旧进程,再根据新的配置文件启动新进程:

Redis的AOF持久化

新进程启动好后会看到对应的aof持久化备份文件appendonly.aof

Redis的AOF持久化

aof追加持久化的备份频率:

[php] view plain copy
 print?
  1. # More details please check the following article:  
  2. # http://antirez.com/post/redis-persistence-demystified.html  
  3. #  
  4. # If unsure, use "everysec".  
  5.   
  6. # appendfsync always  
  7. appendfsync everysec  
  8. # appendfsync no  

2. aof备份文件做优化处理

appendonly.aof文件内容做优化压缩处理:

(例如多个incr指令变为一个set指令)


Redis的AOF持久化

bgrewriteaof  当日志文件过长时优化AOF日志文件存储

Redis的AOF持久化