redis的持久化


################################ 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

 

1. redis是一个内存数据库,当redis服务器重启,获取电脑重启,数据会丢失,我们可以将redis内存中的数据持久化保存到硬盘的文件中。
        2. redis持久化机制:
            1. RDB:默认方式,不需要进行配置,默认就使用这种机制
                * 在一定的间隔时间中,检测key的变化情况,然后持久化数据
                1. 编辑redis.windwos.conf文件
                    #   after 900 sec (15 min) if at least 1 key changed
                    save 900 1
                    #   after 300 sec (5 min) if at least 10 keys changed
                    save 300 10
                    #   after 60 sec if at least 10000 keys changed
                    save 60 10000
                    
                2. 重新启动redis服务器,并指定配置文件名称
                    D:\JavaWeb2018\day23_redis\资料\redis\windows-64\redis-2.8.9>redis-server.exe redis.windows.conf    
                
            2. AOF:日志记录的方式,可以记录每一条命令的操作。可以每一次命令操作后,持久化数据
                1. 编辑redis.windwos.conf文件
                    appendonly no(关闭aof) --> appendonly yes (开启aof)
                    
                    # appendfsync always : 每一次操作都进行持久化
                    appendfsync everysec : 每隔一秒进行一次持久化
                    # appendfsync no     : 不进行持久化

 

最后修改于 2020-02-21 15:15:56
如果觉得我的文章对你有用,请随意赞赏
扫一扫支付
上一篇