1.更改6379.conf文件
[root@localhost redis]# vi 6379.conf //更改如下内容
文件中 daemonize yes //yes改为no 不作为后台进程服务运行
#logfile /var/log/redis_6379.log //次行进行注释,日志会打印到屏幕上
save 900 1
save 300 10
save 60 10000
appendonly yes
aof-use-rdb-preamble no
2.删除原有rdb aof文件
[root@localhost redis6]# cd /var/lib/redis
[root@localhost redis]# ll
总用量 0
drwxr-xr-x. 2 root root 22 3月 7 12:54 6379
drwxr-xr-x. 2 root root 22 3月 8 00:59 6380
[root@localhost redis]# cd 6379
[root@localhost 6379]# ll
总用量 4
-rw-r–r--. 1 root root 104 3月 7 12:54 dump.rdb
[root@localhost 6379]# pwd
/var/lib/redis/6379
[root@localhost 6379]# rm -fr ./*
[root@localhost 6379]# ll
总用量 0
3.启动redis
[root@localhost redis]# redis-server /etc/redis/6379.conf
启动后,如下目录会添加文件:
[root@localhost 6379]# ll
总用量 0
-rw-r–r--. 1 root root 0 3月 8 01:13 appendonly.aof //此文件始内容为空
[root@localhost 6379]# pwd
/var/lib/redis/6379
4.重新打开cmd窗口,启动客户端 设置值
[root@localhost ~]# redis-cli
127.0.0.1:6379> set k1 hello
OK
appendonly.aof //打开此文件 发现有内容
5 rdb文件
127.0.0.1:6379> set k2 world
OK
127.0.0.1:6379> bgsave //触发产生rdb文件
Background saving started
[root@localhost 6379]# pwd
/var/lib/redis/6379
[root@localhost 6379]# ll
总用量 8
-rw-r–r--. 1 root root 87 3月 8 01:22 appendonly.aof
-rw-r–r--. 1 root root 117 3月 8 01:22 dump.rdb //发现产生此文件
控制台出现此日志:
[root@localhost 6379]# vi dump.rdb
查看内容 发现以 REDIS 开头
redis-check-rdb命令检查是否出错:
[root@localhost 6379]# redis-check-rdb dump.rdb
[offset 0] Checking RDB file dump.rdb
[offset 26] AUX FIELD redis-ver = ‘6.2.1’
[offset 40] AUX FIELD redis-bits = ‘64’
[offset 52] AUX FIELD ctime = ‘1615184557’
[offset 67] AUX FIELD used-mem = ‘872104’
[offset 83] AUX FIELD aof-preamble = ‘0’
[offset 85] Selecting DB ID 0
[offset 117] Checksum OK
[offset 117] \o/ RDB looks OK! \o/
[info] 2 keys read
[info] 0 expires
[info] 0 already expired
[root@localhost 6379]#
6重写功能
aof去除没有意义的指令
127.0.0.1:6379> keys *
- “k1”
- “k2”
127.0.0.1:6379> set k1 a
OK
127.0.0.1:6379> set k1 b
OK
127.0.0.1:6379> set k1 c
OK
appendonly.aof 文件会添加很多内容
执行如下内容,appendonly.aof 文件会重写:
127.0.0.1:6379> BGREWRITEAOF
Background append only file rewriting started
==============================
AOF新版本的指令演示:文件内容混合 增量日志+全量实点数据
[root@localhost 6379]# ll
总用量 8
-rw-r–r--. 1 root root 83 3月 8 01:32 appendonly.aof
-rw-r–r--. 1 root root 113 3月 8 01:34 dump.rdb
[root@localhost 6379]# rm -rf ./*
cd /etc/redis
vi 6379.conf
改如下内容:
aof-use-rdb-preamble yes
启动redis:
[root@localhost redis]# redis-server /etc/redis/6379.conf
出现如下文件:
[root@localhost 6379]# ll
总用量 0
-rw-r–r--. 1 root root 0 3月 8 07:32 appendonly.aof
连接客户端 设置一些值:
[root@localhost redis]# redis-cli
127.0.0.1:6379> set k1 a
OK
127.0.0.1:6379> set k1 b
OK
127.0.0.1:6379> set k1 c
OK
127.0.0.1:6379> set k1 d
OK
127.0.0.1:6379> set k1 e
OK
127.0.0.1:6379> BGREWRITEAOF
Background append only file rewriting started
127.0.0.1:6379>
vi appendonly.aof
内容如下:
再设置两个值:
127.0.0.1:6379> set k1 f
OK
127.0.0.1:6379> set k1 g
OK
查看文件 内容如下:
vi appendonly.aof
触发rdb:
127.0.0.1:6379> bgsave
Background saving started
127.0.0.1:6379> BGREWRITEAOF
Background append only file rewriting started
127.0.0.1:6379>
查看文件:
[root@localhost 6379]# ll
总用量 8
-rw-r–r--. 1 root root 103 3月 8 07:53 appendonly.aof
-rw-r–r--. 1 root root 103 3月 8 07:53 dump.rdb
[root@localhost 6379]# pwd
/var/lib/redis/6379
发现两个文件 时间点一样,查看内容发现两者一样。
自动刷新机制:
vi appendonly.aof 可以看到如下内容
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb