1.redis 在运行时,所有的数据都保存在内存里,进程结束以后,会将数据写入到硬盘中。启动时,会读取硬盘里的内容,并将内容全部加载到内存中(会大量占用内存)
2.redis 的持久化有两种形式RDB和AOF
默认为RDB :直接镜像内存里的数据,把内存里的数据保存到dump.rdb文件里,默认在 . / (当前目录下)
[root@iZ0jldi7i29wyph0346wolZ redis-5.0.14]# vim /opt/redis-5.0.14/redis.conf
rdbchecksum yes
dbfilename dump.rdb
#
# 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 ./ # 这个是可修改的,保存路径
save 900 1 #900秒,只要修改,就保存一次
save 300 10 #300秒,如果修改10次,也保存一次
save 60 10000 #60秒,修改次数大于10000次,保存一次
# 有可能导致数据丢失
配置Redis的持久化机制-AOF(append only file),将修改的每一条指令记录进appendonly.aof,需要修改配置文件,来打开aof功能