skip to Main Content

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:

  1. After rewriting the AOF file, does it become a mix of AOF and RDB file?
  2. How can I decode the content of the header?

2

Answers


  1. Chosen as BEST ANSWER

    I did the following experiment:

    1. Stopped Redis Server
    2. Renamed appendonly.aof to dump.rdb
    3. Edited redis.conf, turned off appendonly and turned on save again
    4. Started the server again

    And the server was able to use the dump.rdb, which had only the header, to recreate the database.

    This makes me believe that:

    1. Yes, the AOF file is a mix of AOF and RDB
    2. BGREWRITEAOF doesn't actually rewrite the AOF file, but takes a snapshot instead

  2. You are referring to an AOF file with an RDB preamble. See also here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search