I’m experimenting with Redis and digging into the persistence mechanisms.
If I turn on appendonly (appendonly yes) and turn off RDB (save "") in redis.conf file.
Then I start a new database
And set two keys:
SET firstKey "I'm first one"
SET secondKey "I'm second one"
I end up with an appendonly file without any headers, only commands:
raphaeldelio@Raphaels-MacBook-Pro data % cat appendonly.aof
*2
$6
SELECT
$1
0
*3
$3
SET
$8
firstKey
$14
I'm number one
*3
$3
SET
$9
secondKey
$14
I'm number two
Then, if overwrite the first key with:
SET firstKey "I'm still number one"
And then run BGREWRITEAOF
, the file is rewritten and a header similar to the header of the dump.rdb file is added to it:
raphaeldelio@Raphaels-MacBook-Pro data % cat appendonly.aof
REDIS0009? redis-ver6.2.7?
redis-bits?@?ctimežk?bused-mem˜??
aof-preamble???????֭h
????mʗ????~??ױ??firstKeyI'm still number one secondKeyI'm number two??????֭h
????mʗ??????!4d?%
However, I was expecting the file to be rewritten as command logs again.
Therefore I have two questions:
- After rewriting the AOF file, does it become a mix of AOF and RDB file?
- How can I decode the content of the header?
2
Answers
I did the following experiment:
appendonly.aof
todump.rdb
redis.conf
, turned offappendonly
and turned onsave
againAnd the server was able to use the
dump.rdb
, which had only the header, to recreate the database.This makes me believe that:
BGREWRITEAOF
doesn't actually rewrite the AOF file, but takes a snapshot insteadYou are referring to an AOF file with an RDB preamble. See also here.