zoukankan      html  css  js  c++  java
  • Redis持久化————AOF与RDB模式

     

    1. 1.        官方说明:

     By default Redis asynchronously dumps the dataset on disk. This mode is

     good enough in many applications, but an issue with the Redis process or

     a power outage may result into a few minutes of writes lost (depending on

     the configured save points).

     The Append Only File is an alternative persistence mode that provides

     much better durability. For instance using the default data fsync policy

     (see later in the config file) Redis can lose just one second of writes in a

     dramatic event like a server power outage, or a single write if something

     wrong with the Redis process itself happens, but the operating system is

     still running correctly.

     AOF and RDB persistence can be enabled at the same time without problems.

     If the AOF is enabled on startup Redis will load the AOF, that is the file

     with the better durability guarantees.

     Please check http://redis.io/topics/persistence for more information.

    1. 2.        配置

     redis.conf文件

    #RDB模式配置

    save 900 1     #当有一条Keys数据被改变时,15分钟刷新到Disk一次

    save 300 10    #当有10条Keys数据被改变时,5分钟刷新到Disk一次

    save 60 10000  #当有10000条Keys数据被改变时,1分钟刷新到Disk一次

    #AOF模式配置

    appendonly yes       #启用AOF持久化方式

    appendfilename appendonly.aof  #AOF文件的名称,默认为appendonly.aof

    # appendfsync always  #每次收到写命令就立即强制写入磁盘,是最有保证的完全的持久化,但速度也是最慢的,一般不推荐使用。

    appendfsync everysec #每秒钟强制写入磁盘一次,在性能和持久化方面做了很好的折中,是受推荐的方式。

    # appendfsync no     #完全依赖OS的写入,一般为30秒左右一次,性能最好但是持久化最没有保证,不被推荐。

    no-appendfsync-on-rewrite yes   #在日志重写时,不进行命令追加操作,而只是将其放在缓冲区里,避免与命令的追加造成DISK IO上的冲突。

    auto-aof-rewrite-percentage 100  #当前AOF文件大小是上次日志重写得到AOF文件大小的二倍时,自动启动新的日志重写过程。

    auto-aof-rewrite-min-size 64mb  #当前AOF文件启动新的日志重写过程的最小值,避免刚刚启动Reids时由于文件尺寸较小导致频繁的重写。

    1. 3.        比较测试:

    测试环境下,分别在RDB与AOF模式下,向redis-3.0.7写入同一数值。1秒后,使用killall -9 redis-server模拟生产事故发生。exists命令查看key, AOF模式恢复了kill之前写入的数值,而RDB模式没有恢复。

    参考:http://redis.io/topics/persistence

  • 相关阅读:
    python可视化---plot()函数
    蜂鸣器的相关知识及简单应用
    将一个文件夹中多个视频的视频帧保存在多个文件夹下
    键盘按键控制程序的简单案例
    Tkinter模块的详细总结
    控制LED灯发光
    python socket 套接字编程 单进程服务器 实现多客户端访问
    python 报错RuntimeError: dictionary changed size during iteration
    HTTP请求行、请求头、请求体详解(转)
    python UDP套接字通信
  • 原文地址:https://www.cnblogs.com/lyhero11/p/5319169.html
Copyright © 2011-2022 走看看