How Redis writes data to disk
https://redis.io/docs/management/persistence/
redis持久化的几种方案
Redis 如何将数据写入磁盘
持久性是指将数据写入持久存储,例如固态磁盘 (SSD)。Redis 提供了一系列持久性选项。这些包括:
RDB (Redis Database): RDB persistence performs point-in-time snapshots of your dataset at specified intervals.
在指定的时间间隔,执行数据集的时间点快照
rdb保存的文件:dump.rdb
或者XXXX.rdb
文件,
Redis 6.2
Redis 7
RDB保存时间调整|将持 久化文件RDB的保存规则发生了改变,尤其是时录频度变化
默认配置:save 3600 1 300 100 60 10000
除非另有说明,默认情况下Redis会保存数据库:*3600秒(一小时)后,如果至少执行了一次更改, *300秒(5分钟)后,如果至少执行了100次更改, *60秒后,如果至少执行了10000次更改 ,您可以通过取消对以下行的注释来显式设置这些值。
# save 3600 1300 100 60 10000
默认情况下,如果启用了RDB快照,Redis将停止接受写入(至少一个保存点),并且最近的后台保存失败。这将使用户(以一种艰难的方式)意识到数据没有持久化正确地放在磁盘上,否则。很可能没有人会注意到
默认情况一个小时(3600秒)至少一个 key 变更就记录RDB。
第一步:配置文件写入以下内容
daemonize yes
protected-mode no
#bind 127.0.0.1 -::1
requirepass 123456
save 5 2
dir /root/redis-dump
dbfilename 6379.rdb
第二步:启动服务
第三步:获取配置 CONFIG GET xxxxx
127.0.0.1:6379> CONFIG GET requirepass
1) "requirepass"
2) "123456"
127.0.0.1:6379> CONFIG GET save
1) "save"
2) "5 2"
127.0.0.1:6379> CONFIG GET dir
1) "dir"
2) "/root/redis-dump"
127.0.0.1:6379> CONFIG GET dbfilename
1) "dbfilename"
2) "6379.rdb"
127.0.0.1:6379>
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "xxx!"
127.0.0.1:6379> config get port
1) "port"
2) "6379"
127.0.0.1:6379> config get dir
1) "dir"
2) "/myredis"
127.0.0.1:6379> shutdown
not connected> quit
root@matthew-virtual-machine:/myredis# redis-server /myredis/redis7.conf
238023:C 24 Jan 2024 16:35:50.174 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
root@matthew-virtual-machine:/myredis# redis-cli -a xxx!
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> config get dir
1) "dir"
2) "/myredis/dumpfiles"
验证 5秒2个key是否可以保存文件
127.0.0.1:6379> config get dir
1) "dir"
2) "/myredis/dumpfiles"
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> quit
root@matthew-virtual-machine:/myredis# pwd
/myredis
root@matthew-virtual-machine:/myredis# cd dumpfiles/
root@matthew-virtual-machine:/myredis/dumpfiles# pwd
/myredis/dumpfiles
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 16:40 ./
drwxr-xr-x 3 root root 6 1月 24 16:35 ../
-rw-r--r-- 1 root root 107 1月 24 16:40 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles#
在 set k3 后稍等5s后设置 k4
127.0.0.1:6379> set k3 v3
OK
127.0.0.1:6379> set k4 v4
OK
可以看到 RDB 文件变大了
root@matthew-virtual-machine:/# cd myredis
root@matthew-virtual-machine:/myredis# cd dumpfiles
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 16:40 ./
drwxr-xr-x 3 root root 6 1月 24 16:35 ../
-rw-r--r-- 1 root root 107 1月 24 16:40 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 16:46 ./
drwxr-xr-x 3 root root 6 1月 24 16:35 ../
-rw-r--r-- 1 root root 121 1月 24 16:46 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles#
第一步:备份RDB文件,然后执行 FLUSHALL 命令清空数据。
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379>
drwxr-xr-x 2 root root 3 1月 24 16:40 ./
drwxr-xr-x 3 root root 6 1月 24 16:35 ../
-rw-r--r-- 1 root root 107 1月 24 16:40 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 16:46 ./
drwxr-xr-x 3 root root 6 1月 24 16:35 ../
-rw-r--r-- 1 root root 121 1月 24 16:46 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 11
drwxr-xr-x 2 root root 3 1月 24 16:48 ./
drwxr-xr-x 3 root root 6 1月 24 16:35 ../
-rw-r--r-- 1 root root 88 1月 24 16:48 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles#
第二步:执行 SHUTDOWN 命令,也会产生一个 RDB 文件。
127.0.0.1:6379> shutdown
not connected> quit
root@matthew-virtual-machine:/myredis#
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 17:14 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 121 1月 24 17:14 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# mv dump6379.rdb dump6379.rdb.bak
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 17:15 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 121 1月 24 17:14 dump6379.rdb.bak
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 16
drwxr-xr-x 2 root root 4 1月 24 17:15 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 88 1月 24 17:15 dump6379.rdb
-rw-r--r-- 1 root root 121 1月 24 17:14 dump6379.rdb.bak
root@matthew-virtual-machine:/myredis/dumpfiles#
删除关机时的RDB
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 17:22 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 121 1月 24 17:22 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# mv dump6379.rdb dump6379.rdb.bak
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 17:23 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 121 1月 24 17:22 dump6379.rdb.bak
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 17:23 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 121 1月 24 17:22 dump6379.rdb.bak
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 16
drwxr-xr-x 2 root root 4 1月 24 17:23 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 88 1月 24 17:23 dump6379.rdb
-rw-r--r-- 1 root root 121 1月 24 17:22 dump6379.rdb.bak
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 16
drwxr-xr-x 2 root root 4 1月 24 17:24 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 88 1月 24 17:24 dump6379.rdb
-rw-r--r-- 1 root root 121 1月 24 17:22 dump6379.rdb.bak
root@matthew-virtual-machine:/myredis/dumpfiles# mv dump6379.rdb.bak dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 17:24 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 121 1月 24 17:22 dump6379.rdb
第三步:将备份的RDB文件名称改回去,同时重启Redis服务,验证 key 是否恢复。
127.0.0.1:6379> keys *
1) "k3"
2) "k1"
3) "k4"
4) "k2"
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> shutdown
not connected> quit
// 修改 mv dump6379.rdb.bak dump6379.rdb
root@matthew-virtual-machine:/myredis# redis-server /myredis/redis7.conf
root@matthew-virtual-machine:/myredis# redis-cli -a xxx!
127.0.0.1:6379> keys *
1) "k3"
2) "k2"
3) "k4"
4) "k1"
总结:物理恢复,一定要服务和备份分机隔离。
Tips:生产环境不能使用 save 命令,会阻塞主线程。
Redis提供了两个命令来生成RDB文件,分别是save和bgsave
在主程序中执行会阻塞当前redis服务器,直到持久化工作完成执行save命令期间,Redis不 能处理其他命令,线上禁止使用
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> save
OK
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 17:24 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 121 1月 24 17:22 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# rm -rf dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 10
drwxr-xr-x 2 root root 2 1月 24 17:29 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 11
drwxr-xr-x 2 root root 3 1月 24 17:29 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 88 1月 24 17:29 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 11
drwxr-xr-x 2 root root 3 1月 24 17:29 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 100 1月 24 17:29 dump6379.rdb
Redis会在后台异步进行快照操作,不阻塞快照同时还可以响应客户端请求,该触发方式会fork一个子进程由子进程复制持久化过程
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> bgsave
Background saving started
127.0.0.1:6379>
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 11
drwxr-xr-x 2 root root 3 1月 24 17:29 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 100 1月 24 17:29 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# ll
总用量 15
drwxr-xr-x 2 root root 3 1月 24 17:30 ./
drwxr-xr-x 3 root root 6 1月 24 17:04 ../
-rw-r--r-- 1 root root 107 1月 24 17:30 dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles#
127.0.0.1:6379> lastsave
(integer) 1706088652
date -d @时间戳
root@matthew-virtual-machine:/myredis/dumpfiles# date -d @1706088652
2024年 01月 24日 星期三 17:30:52 CST
优点:https://redis.io/docs/management/persistence/#rdb-advantages
缺点:https://redis.io/docs/management/persistence/#rdb-disadvantages
redis-check-rdb /root/redis-dump/dump6379.rdb
root@matthew-virtual-machine:/myredis/dumpfiles# cd /usr/local/bin
root@matthew-virtual-machine:/usr/local/bin# ll
总用量 21156
drwxr-xr-x 2 root root 8 1月 16 09:34 ./
drwxr-xr-x 11 root root 12 10月 14 22:42 ../
-rwxr-xr-x 1 root root 10806320 1月 16 09:34 redis-benchmark*
lrwxrwxrwx 1 root root 12 1月 16 09:34 redis-check-aof -> redis-server*
lrwxrwxrwx 1 root root 12 1月 16 09:34 redis-check-rdb -> redis-server*
-rwxr-xr-x 1 root root 11355632 1月 16 09:34 redis-cli*
lrwxrwxrwx 1 root root 12 1月 16 09:34 redis-sentinel -> redis-server*
-rwxr-xr-x 1 root root 22982200 1月 16 09:34 redis-server*
root@matthew-virtual-machine:/usr/local/bin#
root@matthew-virtual-machine:/usr/local/bin# redis-check-rdb /root/redis-dump/dump6379.rdb
[offset 0] Checking RDB file /root/redis-dump/dump6379.rdb
save
、bgsave
flushall
、flushdb
,但里面是空的。shutdown
config set save ""
,命令级别save ""
,配置文件# However if you have setup your proper monitoring of the Redis server
# and persistence, you may want to disable this feature so that Redis will
# continue to work as usual even if there are problems with disk,
# permissions, and so forth.
stop-writes-on-bgsave-error yes
# Compress string objects using LZF when dump .rdb databases?
# By default compression is enabled as it's almost always a win.
# If you want to save some CPU in the saving child set it to 'no' but
# the dataset will likely be bigger if you have compressible values or keys.
rdbcompression yes
# RDB files created with checksum disabled have a checksum of zero that will
# tell the loading code to skip the check.
rdbchecksum yes
# An alternative (and sometimes better) way to obtain the same effect is
# to use diskless replication on both master and replicas instances. However
# in the case of replicas, diskless is not always an option.
rdb-del-sync-files no
总结:
AOF (Append Only File): AOF persistence logs every write operation received by the server. These operations can then be replayed again at server startup, reconstructing the original dataset. Commands are logged using the same format as the Redis protocol itself.
AOF 持久性记录服务器接收的每个写入操作。然后,可以在服务器启动时再次重播这些操作,从而重建原始数据集。使用与 Redis 协议本身相同的格式记录命令。
# appendfsync always
appendfsync everysec
# appendfsync no
always
同步写回,每个写命令执行完立刻同步地将日志写回磁盘
everysec
默认!!!
每秒写回,每个写命令执行完,只是先把日志写到AOF文件的内存缓冲区,每隔1秒把缓冲区中的内容写入磁盘
no
操作系统控制的写回,每个写命令执行完,只是先把日志写到AOF文件的内存缓冲区,由操作系统决定何时将缓冲区内容写回磁盘
安全性:always
> everysec
> no
性能:no
> everysec
> always
#appendonly no
appendonly yes
redis6
:RDB和AOF,dir目录共享同一个dir。且 AOF 文件只有一个。
redis7
:三个AOF文件,
appendfilename "appendonly.aof"
# For convenience, Redis stores all persistent append-only files in a dedicated
# directory. The name of the directory is determined by the appenddirname
# configuration parameter.
appenddirname "appendonlydir"
Muti-part AOF
# - appendonly.aof.1.base.rdb as a base file.
# - appendonly.aof.1.incr.aof, appendonly.aof.2.incr.aof as incremental files.
# - appendonly.aof.manifest as a manifest file.
base表示基础AOF
,INCR
表示增量AOF
,manifest
127.0.0.1:6379> config get appendonly
1) "appendonly"
2) "no"
127.0.0.1:6379> config get appendonly
1) "appendonly"
2) "yes"
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> save
OK
drwxr-xr-x 4 root root 7 1月 24 19:26 ./
drwxr-xr-x 20 root root 26 1月 16 09:40 ../
drwxr-xr-x 2 root root 5 1月 24 19:26 appendonlydir/
drwxr-xr-x 2 root root 3 1月 24 19:21 dumpfiles/
-rw-r--r-- 1 root root 353 1月 24 16:35 dump.rdb
-rw-r--r-- 1 root root 107561 1月 24 19:25 redis7.conf
-rw-r--r-- 1 root root 24576 1月 16 09:46 .redis7.conf.swp
root@matthew-virtual-machine:/myredis# ll
总用量 108
drwxr-xr-x 4 root root 8 1月 24 19:27 ./
drwxr-xr-x 20 root root 26 1月 16 09:40 ../
drwxr-xr-x 2 root root 5 1月 24 19:26 appendonlydir/
-rw-r--r-- 1 root root 100 1月 24 19:27 dump6379.rdb
drwxr-xr-x 2 root root 3 1月 24 19:21 dumpfiles/
-rw-r--r-- 1 root root 353 1月 24 16:35 dump.rdb
-rw-r--r-- 1 root root 107561 1月 24 19:25 redis7.conf
-rw-r--r-- 1 root root 24576 1月 16 09:46 .redis7.conf.swp
root@matthew-virtual-machine:/myredis# cd appendonlydir/
root@matthew-virtual-machine:/myredis/appendonlydir# ll
总用量 21
drwxr-xr-x 2 root root 5 1月 24 19:26 ./
drwxr-xr-x 4 root root 8 1月 24 19:27 ../
-rw-r--r-- 1 root root 88 1月 24 19:26 appendonly.aof.1.base.rdb
-rw-r--r-- 1 root root 52 1月 24 19:27 appendonly.aof.1.incr.aof
-rw-r--r-- 1 root root 88 1月 24 19:26 appendonly.aof.manifest
root@matthew-virtual-machine:/myredis/appendonlydir#
测试:
127.0.0.1:6379> keys *
(empty array)
127.0.0.1:6379> set k1 v1
OK
127.0.0.1:6379> set k2 v2
OK
127.0.0.1:6379> set k3 v3
OK
127.0.0.1:6379> set k4 v4
OK
127.0.0.1:6379> flushall
OK
127.0.0.1:6379> shutdown
not connected> quit
root@matthew-virtual-machine:/myredis# redis-server /myredis/redis7.conf
17713:C 24 Jan 2024 19:41:43.076 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
root@matthew-virtual-machine:/myredis# redis-cli -a 1186981212xxx!
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
127.0.0.1:6379> keys *
1) "k3"
2) "k4"
3) "k1"
4) "k2"
127.0.0.1:6379>
root@matthew-virtual-machine:/myredis# cp -r appendonlydir/ appendonlydir.bak
root@matthew-virtual-machine:/myredis# ll
总用量 112
drwxr-xr-x 4 root root 8 1月 24 19:39 ./
drwxr-xr-x 20 root root 26 1月 16 09:40 ../
drwxr-xr-x 3 root root 6 1月 24 19:35 appendonlydir/
drwxr-xr-x 3 root root 6 1月 24 19:39 appendonlydir.bak/
-rw-r--r-- 1 root root 121 1月 24 19:38 dump6379.rdb
-rw-r--r-- 1 root root 353 1月 24 16:35 dump.rdb
-rw-r--r-- 1 root root 107561 1月 24 19:25 redis7.conf
-rw-r--r-- 1 root root 24576 1月 16 09:46 .redis7.conf.swp
root@matthew-virtual-machine:/myredis# rm -f dump6379.rdb
root@matthew-virtual-machine:/myredis# ll
总用量 115
drwxr-xr-x 4 root root 7 1月 24 19:40 ./
drwxr-xr-x 20 root root 26 1月 16 09:40 ../
drwxr-xr-x 3 root root 6 1月 24 19:35 appendonlydir/
drwxr-xr-x 3 root root 6 1月 24 19:39 appendonlydir.bak/
-rw-r--r-- 1 root root 353 1月 24 16:35 dump.rdb
-rw-r--r-- 1 root root 107561 1月 24 19:25 redis7.conf
-rw-r--r-- 1 root root 24576 1月 16 09:46 .redis7.conf.swp
root@matthew-virtual-machine:/myredis# rm -rf appendonlydir/
root@matthew-virtual-machine:/myredis# ll
总用量 106
drwxr-xr-x 3 root root 6 1月 24 19:41 ./
drwxr-xr-x 20 root root 26 1月 16 09:40 ../
drwxr-xr-x 3 root root 6 1月 24 19:39 appendonlydir.bak/
-rw-r--r-- 1 root root 353 1月 24 16:35 dump.rdb
-rw-r--r-- 1 root root 107561 1月 24 19:25 redis7.conf
-rw-r--r-- 1 root root 24576 1月 16 09:46 .redis7.conf.swp
root@matthew-virtual-machine:/myredis# mv appendonlydir.bak/ appendonlydir
root@matthew-virtual-machine:/myredis# ll
drwxr-xr-x 3 root root 6 1月 24 19:41 ./
drwxr-xr-x 20 root root 26 1月 16 09:40 ../
drwxr-xr-x 3 root root 6 1月 24 19:39 appendonlydir/
-rw-r--r-- 1 root root 353 1月 24 16:35 dump.rdb
-rw-r--r-- 1 root root 107561 1月 24 19:25 redis7.conf
-rw-r--r-- 1 root root 24576 1月 16 09:46 .redis7.conf.swp
root@matthew-virtual-machine:/myredis#
故意乱写 AOF 模拟错误情况
修改文件后重启 redis 发现启动错误
本身的配置文件都有错误!!!
redis-check-aof appendonly.aof.1.incr.aof
redis-check-aof --fix appendonly.aof.1.incr.aof
修复后重新启动
AOF优点:https://redis.io/docs/management/persistence/#aof-advantages
AOF缺点:https://redis.io/docs/management/persistence/#aof-disadvantages
Redis < 7.0
简单说:AOF更安全,更慢
是什么: 让 AOF 文件瘦身,更精简。
由于AOF持久化是Redis不断将写命令记录到AOF文件中,随着Redis不断的进行,AOF的文件会越来越大,文件越大,占用服务器内存越大以及AOF恢复要求时间越长。
为了解决这个问题,Redis新增了重写机制,当AOF文件的大小超过所设定的峰值时,Redis就会自动启动AOF文件的内容压缩,只保留可以恢复数据的最小指令集或者可以手动使用命令 BGREWRITEAOF
来重新。
手动触发命令
BGREWRITEAOF
自动触发默认配置
# Automatic rewrite of the append only file.
# Redis is able to automatically rewrite the log file implicitly calling
# BGREWRITEAOF when the AOF log size grows by the specified percentage.
#
# This is how it works: Redis remembers the size of the AOF file after the
# latest rewrite (if no rewrite has happened since the restart, the size of
# the AOF at startup is used).
#
# This base size is compared to the current size. If the current size is
# bigger than the specified percentage, the rewrite is triggered. Also
# you need to specify a minimal size for the AOF file to be rewritten, this
# is useful to avoid rewriting the AOF file even if the percentage increase
# is reached but it is still pretty small.
#
# Specify a percentage of zero in order to disable the automatic AOF
# rewrite feature.
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
将文件改为1k
auto-aof-rewrite-min-size 1k
将 aof-use-rdb-preamble 改为 no ,默认为 yes
# Redis can create append-only base files in either RDB or AOF formats. Using
# the RDB format is always faster and more efficient, and disabling it is only
# supported for backward compatibility purposes.
#aof-use-rdb-preamble yes
aof-use-rdb-preamble no
删除之前的 AOF 后启动
不断执行写入命令,
写入操作会持续增大 aof 文件大小
当到达 1k的时候,
vim appendonly.aof.2.base.aof
#appendonly no
appendonly yes
appendfilename "appendonly.aof"
appenddirname "appendonlydir"
# appendfsync always
appendfsync everysec
# appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
#auto-aof-rewrite-min-size 64mb
auto-aof-rewrite-min-size 1k
aof-load-truncated yes
https://redis.io/docs/management/persistence/#ok-so-what-should-i-use
同时开启 rdb 和 aof ,aof 优先级高于 rdb
开启
#aof-use-rdb-preamble yes
是什么:不进行持久化 同时关闭RDB和AOF
save ""
appendonly no
禁用自动触发,仍然可以使用命令保存 RDB 和 AOF 文件。