dump.rdb 与 appendonly.aof 同时存在的情况下,默认优先读取appendonly.aof文件。如果appendonly.aof有错误,则启动会失败。
vim appendonly.aof
*2
$6
SELECT
$1
...
v3
dfsdfsdfsdfsdfsd;;;;;;;;sdfsdf;;;;;;;sd;f;;; // 乱加的
启动失败:
[mhbtest@root redis-5.0.4]$ src/redis-server redis_aof.conf
19838:C 15 Dec 2020 16:37:13.330 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
19838:C 15 Dec 2020 16:37:13.330 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=19838, just started
19838:C 15 Dec 2020 16:37:13.330 # Configuration loaded
[mhbtest@root redis-5.0.4]$ src/redis-cli -p 6379
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
通过命令 redis-check-aof
启动成功:
[mhbtest@root redis-5.0.4]$ src/redis-check-aof --fix appendonly.aof
0x 6e: Expected prefix '*', got: 'd'
AOF analyzed: size=156, ok_up_to=110, diff=46
This will shrink the AOF from 156 bytes, with 46 bytes, to 110 bytes
Continue? [y/N]: y
Successfully truncated AOF
[mhbtest@root redis-5.0.4]$ src/redis-server redis_aof.conf
22117:C 15 Dec 2020 16:41:25.754 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
22117:C 15 Dec 2020 16:41:25.754 # Redis version=5.0.4, bits=64, commit=00000000, modified=0, pid=22117, just started
22117:C 15 Dec 2020 16:41:25.754 # Configuration loaded
[mhbtest@root redis-5.0.4]$ src/redis-cli -p 6379
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>