0
0
Redisquery~5 mins

AOF (Append Only File) in Redis

Choose your learning style9 modes available
Introduction

AOF helps save every change made to your Redis database so you don't lose data if the server stops unexpectedly.

You want to keep a detailed record of all changes to recover data after a crash.
You need to ensure data durability for important information like user sessions or shopping carts.
You want to replay commands to rebuild the database state after restarting Redis.
You want a safer alternative to just saving snapshots occasionally.
You want to track changes in real-time for auditing or debugging.
Syntax
Redis
appendonly yes|no
appendfilename filename.aof
appendfsync always|everysec|no

appendonly yes|no turns AOF on or off.

appendfsync controls how often Redis writes to disk: always (slow but safe), everysec (balanced), or no (fast but risky).

Examples
This enables AOF, sets the file name, and writes changes every second for good balance.
Redis
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
This disables AOF, so Redis won't save every command, only snapshots.
Redis
appendonly no
Sample Program

This configuration turns on AOF, names the file 'mydata.aof', and writes changes every second to keep data safe without slowing Redis too much.

Redis
# redis.conf example
appendonly yes
appendfilename mydata.aof
appendfsync everysec
OutputSuccess
Important Notes

AOF files grow over time; Redis can rewrite them to keep size small.

Using appendfsync always is safest but can slow Redis down.

Combining AOF with snapshots gives extra safety.

Summary

AOF saves every change to keep your data safe.

You can control how often Redis writes to disk for speed or safety.

AOF helps recover your database after crashes by replaying commands.