Redis数据持久化
2016-08-15 11:16
260 查看
redis的持久化有rdb和aof两种。
rdb是记录一段时间内的操作,一盘的配置是一段时间内操作超过多少次就持久化。
aof可以实现每次操作都持久化。
这里我们使用aof。
配置方式,打开redis的配置文件。找到appendonly。默认是appendonly no。改成appendonly yes。
再找到appendfsync
默认是:
默认每秒持久化满足我的需求。
其实改下appendonly 就ok了。
附:redis dump.rdb appendonly.aof 文件路径修改:
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./
-------------------------
这里默认是启动后的相对路径也就是你的redis在哪里启动,dump.rdb 文件或者appendonly.aof
文件就会产生在启动所在的目录;
这也就是有些人重启后key值消失的原因,那是因为又产生了其他ump.rdb 文件或者appendonly.aof
这里建议改成绝对路径
dir /usr/local/redis/data/
rdb是记录一段时间内的操作,一盘的配置是一段时间内操作超过多少次就持久化。
aof可以实现每次操作都持久化。
这里我们使用aof。
配置方式,打开redis的配置文件。找到appendonly。默认是appendonly no。改成appendonly yes。
再找到appendfsync
默认是:
# appendfsync always #每次收到写命令就立即强制写入磁盘,最慢的,但是保证完全的持久化,不推荐使用 appendfsync everysec #每秒钟强制写入磁盘一次,在性能和持久化方面做了很好的折中,推荐 # appendfsync no #完全依赖os,性能最好,持久化没保证
默认每秒持久化满足我的需求。
其实改下appendonly 就ok了。
附:redis dump.rdb appendonly.aof 文件路径修改:
# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir ./
-------------------------
这里默认是启动后的相对路径也就是你的redis在哪里启动,dump.rdb 文件或者appendonly.aof
文件就会产生在启动所在的目录;
这也就是有些人重启后key值消失的原因,那是因为又产生了其他ump.rdb 文件或者appendonly.aof
这里建议改成绝对路径
dir /usr/local/redis/data/