zoukankan      html  css  js  c++  java
  • Redis持久化

    1、redis持久化有两种方式:分别是RDB(Redis DataBase)和AOF(Append Only File)
        RDB,简而言之,就是在不同的时间点,将redis存储的数据生成快照并存储到磁盘等介质上;
        AOF,则是换了一个角度来实现持久化,那就是将redis执行过的所有写指令记录下来。
        在下次redis重新启动时,只要把这些写指令从前到后再重复执行一遍,就可以实现数据恢复了。
    2、其实RDB和AOF两种方式也可以同时使用,在这种情况下,如果redis重启的话,则会优先采用AOF方式来进行数据恢复,
        这是因为AOF方式的数据恢复完整度更高。如果你没有数据持久化的需求,也完全可以关闭RDB和AOF方式,
        这样的话,redis将变成一个纯内存数据库,就像memcache一样。
    3、RDB和AOF的配置如下:
        [root@localhost redis-3.2.6]# more redis.conf|grep rdb
        # Compress string objects using LZF when dump .rdb databases?
        rdbcompression yes
        rdbchecksum yes
        dbfilename dump.rdb
        
        [root@localhost redis-3.2.6]# more redis.conf|grep appendonly
        appendonly no
        # The name of the append only file (default: "appendonly.aof")
        appendfilename "appendonly.aof"
    4、保存策略,默认有三个:
        save 900 1 
        save 300 10 
        save 60 10000 
        分别表示的意思如下:
        至少有1个key被更改时,900秒后保存
        至少有10个key被更改时,300秒后保存
        至少有10000个key被更改时,60秒后保存
    5、如果不想持久化,把这三个保存策略注释掉,即可。
        取消持久化,当重启redis服务的时候,之前设置的key都不存在了。
    
  • 相关阅读:
    每天读一下,你就会改变
    C++ 反转字符串(原创)
    C++ string学习
    18种常见室内花卉的功效 (转自网络)
    UML建模教程
    孙鑫视频VC++深入详解学习笔记
    visual C++ 6.0开发工具与调试
    C++ typeid typename使用
    C++模板学习
    Working classes Code complete reading notes(6)
  • 原文地址:https://www.cnblogs.com/nzbbody/p/6389604.html
Copyright © 2011-2022 走看看