0
0
RedisHow-ToBeginner · 3 min read

How to Configure AOF Persistence in Redis for Data Durability

To configure AOF persistence in Redis, enable it by setting appendonly yes in the redis.conf file. You can customize how often Redis writes to the AOF file using appendfsync options like always, everysec, or no.
📐

Syntax

The main configuration for AOF persistence is done in the redis.conf file with these directives:

  • appendonly yes|no: Enables or disables AOF persistence.
  • appendfilename <filename>: Sets the name of the AOF file (default is appendonly.aof).
  • appendfsync always|everysec|no: Controls how often Redis writes AOF data to disk.
conf
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
💻

Example

This example shows how to enable AOF persistence with Redis writing to disk every second for a good balance between performance and durability.

conf
# redis.conf snippet
appendonly yes
appendfilename appendonly.aof
appendfsync everysec
⚠️

Common Pitfalls

Common mistakes when configuring AOF persistence include:

  • Forgetting to set appendonly yes, so AOF is not enabled.
  • Using appendfsync always which can slow Redis due to frequent disk writes.
  • Not restarting Redis after changing redis.conf, so changes do not apply.
  • Ignoring AOF file growth, which can become large without periodic rewriting.
conf
## Wrong: AOF disabled
appendonly no

## Right: AOF enabled with balanced fsync
appendonly yes
appendfsync everysec
📊

Quick Reference

DirectiveDescriptionTypical Values
appendonlyEnable or disable AOF persistenceyes, no
appendfilenameName of the AOF fileappendonly.aof
appendfsyncFrequency of fsync to diskalways, everysec, no
auto-aof-rewrite-percentageRewrite AOF when file grows by %100
auto-aof-rewrite-min-sizeMinimum AOF size to trigger rewrite64mb

Key Takeaways

Enable AOF by setting 'appendonly yes' in redis.conf to persist data.
Use 'appendfsync everysec' for a good balance of durability and performance.
Restart Redis after changing AOF settings to apply them.
Monitor AOF file size and configure automatic rewriting to prevent large files.
Avoid 'appendfsync always' unless strict durability is required, as it impacts performance.