Redis全方位详解--磁盘持久化和容灾备份

  在上一篇博客中,博客介绍了redis的数据类型使用场景和redis分布式锁的正确姿势。我们知道一旦Redis重启,存在redis里面的数据就会全部丢失。所以这篇博客中向大家介绍Redis磁盘持久化。

 

REDIS持久化

  以每隔一段时间对redis进行快照的方式实现持久化

RDB持久化

  优点:1、对redis性能影响小。

     2、数据集比较大的时候,恢复速度比AOF快。

       3、RDB是一个非常紧凑的单一文件,很方便传到第三方数据中心(亚马逊S3),以便日后的灾难恢复。

  缺点:1、因为RDB的快照持久化方式,所以一旦出现宕机,你可能丢失几分钟的数据。

     2、RDB需要fork一个子进程来保存数据集到磁盘上,所以当数据集比较大的时候,就会造成redis在毫秒级内对客户端没反应。

  配置文件:在redis.conf文件中,有这样一段话。

################################ SNAPSHOTTING ################################ # # Save the DB on disk: # # save <seconds> <changes> # # Will save the DB if both the given number of seconds and the given # number of write operations against the DB occurred. # # In the example below the behaviour will be to save: # after 900 sec (15 min) if at least 1 key changed # after 300 sec (5 min) if at least 10 keys changed # after 60 sec if at least 10000 keys changed # # Note: you can disable saving completely by commenting out all "save" lines. # # It is also possible to remove all the previously configured save # points by adding a save directive with a single empty string argument # like in the following example: # # save "" save 900 1 save 300 10 save 60 10000

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpgwsx.html