.aof — AOF (Append-Only File) Format
Redis Labs · 2009
The AOF format logs every write operation to a Redis database, ensuring data durability by allowing reconstruction of the dataset.
Key Features
- Records every write operation for high durability.
- Allows for data reconstruction by replaying commands.
- Supports different fsync policies for trade-offs.
- Can be rewritten to optimize file size.
Best For
- Users prioritizing data durability over disk space.
- Applications requiring minimal data loss.
- Maintaining a complete history of database modifications.
Less Ideal For
- Situations where disk space is severely limited.
- Very high-write environments where AOF growth is a concern.
- When only occasional data backups are needed (RDB might be sufficient).
Common Use Cases
- Ensuring data persistence for critical Redis databases.
- Providing a highly durable storage mechanism for in-memory data.
- Reconstructing database state after server restarts or crashes.
- Auditing write operations performed on a Redis instance.
How to Open It
- Directly viewable as a text file in editors like `cat`, `less`, or Notepad++ to inspect commands.
- Replayed by a Redis server during startup if configured to load AOF.
- Can be processed by `redis-check-aof` for integrity checks.
- Use `redis-cli --pipe < aof_file.aof` for manual replay.
What is a .aof file?
The Append-Only File (AOF) format is a specialized file used by the Redis in-memory data structure store. Instead of storing a snapshot of the database, AOF records every write operation received by the server. This log of commands allows Redis to reconstruct the dataset accurately. While it can be larger than a snapshot, AOF typically offers better durability, ensuring fewer data losses in case of unexpected shutdowns. It's a core feature for ensuring data persistence in Redis deployments.
Programs That Open .aof Files
| Platform | Program | ||
|---|---|---|---|
| Windows | Redis Server | Free | Official |
| Notepad++ | Free | ||
| macOS | Redis Server | Free | Official |
| TextEdit | Free | Official | |
| Linux | Redis Server | Free | Official |
| GNU nano | Free |
Common Problems with .aof Files
Frequently Asked Questions
RDB creates point-in-time snapshots of the dataset, while AOF logs every write operation. AOF generally offers better durability as it records changes more frequently, reducing potential data loss.
While technically possible as it's a text file, it's strongly discouraged. Manual edits can easily corrupt the file and lead to data inconsistencies or complete loss when Redis tries to load it.
When `BGREWRITEAOF` is called, Redis forks a child process that builds a new, compacted AOF file containing only the commands necessary to reconstruct the current dataset, effectively removing obsolete commands.
Technical Details
AOF files are essentially a sequence of Redis commands (like SET, DEL, RPUSH) that, when replayed, rebuild the exact state of the database. Redis can use different AOF rewriting strategies (e.g., BGREWRITEAOF) to compact the file periodically, reducing its size by removing redundant commands. The file can be written in different modes, such as `always`, `everysec`, or `no`, affecting durability and performance trade-offs.