AppendOnlyFile in Redis logs every write operation done to the redis database.

My Question is that when we delete data from the redis database, are those operations logged in the AppendOnlyFile ? And the data which is deleted from the database, is the record corresponding to that data in the AppendOnlyFile is also deleted?

For example,

I set a key, > set a apple

This will be logged in the AppendOnlyFile, suppose as "Log:set:a:apple"

Now, If I do, > del a

What will this do? Will a log corresponding to this be made, like "Log:del:a" ? And once we delete the key, will the log "Log:set:a:apple" also get deleted ?


Yes. Every modification (also delete) of data gets written to AOF. See Redis persistence demystified blog posting.

Append only file The Append Only File, usually called simply AOF, is the main Redis persistence option. The way it works is extremely simple: every time a write operation that modifies the dataset in memory is performed, the operation gets logged. The log is produced exactly in the same format used by clients to communicate with Redis, so the AOF can be even piped via netcat to another instance, or easily parsed if needed. At restart Redis re-plays all the operations to reconstruct the dataset.

To show how the AOF works in practice I'll do a simple experiment, setting up a new Redis 2.6 instance with append only file enabled:

./redis-server --appendonly yes

Now it's time to send a few write commands to the instance:

redis> set key1 Hello
redis> append key1 " World!"
(integer) 12
redis> del key1
(integer) 1
redis> del non_existing_key
(integer) 0

The first three operations actually modified the dataset, the fourth did not, because there was no key with the specified name. This is how our append only file looks like:

$ cat appendonly.aof 

As you can see the final DEL is missing, because it did not produced any modification to the dataset.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.