Question

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,

127.0.0.1:6379 > set a apple

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

Now, If I do,

127.0.0.1:6379 > 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 ?

Was it helpful?

Solution

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 127.0.0.1:6379> set key1 Hello
OK
redis 127.0.0.1:6379> append key1 " World!"
(integer) 12
redis 127.0.0.1:6379> del key1
(integer) 1
redis 127.0.0.1:6379> 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 
*2
$6
SELECT
$1
0
*3
$3
set
$4
key1
$5
Hello
*3
$6
append
$4
key1
$7
 World!
*2
$3
del
$4
key1

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

Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top