Introduction
Redis is often categorized as an in-memory data store, but dismissing its persistence capabilities would be a mistake. With 74,000+ GitHub stars and continuous active development (last updated June 2026), Redis supports multiple robust persistence mechanisms that make it suitable for use cases far beyond simple caching — from session stores to primary databases. This guide compares the three main Redis persistence strategies: RDB point-in-time snapshots, AOF (Append-Only File) command logging, and the hybrid approach that combines both. We also explore backup tooling for production-grade data protection.
Understanding Redis Persistence
Redis persistence is not an all-or-nothing choice. The three mechanisms can be used individually or in combination, each offering different trade-offs between durability, performance, and recovery speed.
Comparison Table
| Feature | RDB Snapshots | AOF Logs | Hybrid (RDB + AOF) |
|---|---|---|---|
| Persistence type | Periodic full snapshots | Continuous command log | Both |
| Data loss window | Minutes (between saves) | 1 second (with fsync everysec) | ~1 second |
| Recovery speed | Fast (loads binary dump) | Slower (replays all commands) | Fast (uses RDB base + AOF tail) |
| File size | Compact (compressed) | Large (grows with write volume) | Moderate |
| CPU overhead | High during snapshot (fork + save) | Low (sequential writes) | Moderate |
| Disk I/O | Burst (during save) | Steady stream | Both |
| Best for | Cache data, disaster recovery | Transactional data, audit trails | Primary database workloads |
| Rewrite needed | No | Yes (BGREWRITEAOF) | Periodic |
| Compatible with replication | Yes | Yes | Yes |
Strategy 1: RDB (Redis Database) Snapshots
RDB persistence creates point-in-time snapshots of your dataset at specified intervals. Redis forks a child process that writes the entire in-memory dataset to a compact binary file (dump.rdb). The parent process continues serving requests without interruption.
| |
Manual snapshot triggering:
| |
Verifying RDB integrity:
| |
Docker Compose with RDB persistence:
| |
Key advantage: RDB files are compact, portable, and perfect for disaster recovery. You can copy a single file to any Redis instance and restore within seconds. They’re also ideal for promoting a replica to primary during failover.
Key limitation: If Redis crashes between snapshots, you lose all writes since the last save. The more frequently you save, the more CPU and I/O you consume on forking — for large datasets (10GB+), fork time can spike to seconds.
Strategy 2: AOF (Append-Only File) Logging
AOF logs every write operation received by the server to a persistent file. On restart, Redis replays the log to reconstruct the dataset. This provides much stronger durability guarantees than RDB at the cost of larger files and slightly slower recovery.
| |
The three fsync policies explained:
| Policy | Durability | Performance | Use Case |
|---|---|---|---|
always | Every write is fsynced | Slowest (~30K ops/sec) | Financial data, audit logs |
everysec | Lose at most 1 second of data | Good (~80K ops/sec) | Default for most workloads |
no | OS decides when to flush | Fastest (~100K ops/sec) | Cache data, non-critical workloads |
AOF rewrite — keeping the log manageable:
Over time, the AOF file grows with every write command. BGREWRITEAOF creates a compact version containing only the minimal set of commands to reconstruct the current dataset:
| |
Multi-part AOF (Redis 7.0+):
Redis 7.0 introduced multi-part AOF, storing the base file and incremental changes separately:
| |
This hybrid approach combines RDB’s fast loading with AOF’s durability — the base file loads quickly as an RDB, and only the small incremental AOF needs replaying.
Verifying AOF integrity:
| |
Strategy 3: Backup Tools for Production
Beyond Redis’s built-in persistence, third-party tools add automation, compression, and cloud storage integration.
redis-dump — Export to JSON for portability:
| |
Automated backup script with S3 upload:
| |
Docker Compose with automated backup sidecar:
| |
Why Self-Host Redis with Custom Persistence
Managed Redis services (ElastiCache, Memorystore, Upstash) abstract away persistence configuration — but they also abstract away your control. Cloud providers typically set conservative RDB save intervals (often 15 minutes minimum) and may not expose AOF configuration at all. For applications where data consistency matters — user sessions, cart data, rate limit counters — losing up to 15 minutes of writes during a failure is unacceptable.
Self-hosting Redis gives you full control over the persistence strategy. You can tune appendfsync always for financial transaction data while using RDB snapshots for less critical cache content — all on the same instance. Combined with Redis high availability configurations, a self-hosted setup can achieve durability guarantees that rival traditional SQL databases.
For monitoring your persistence health, integrating with Redis management UIs provides visibility into BGSAVE duration, AOF rewrite status, and replication lag. When persistence operations start taking longer than expected, these dashboards alert you before a production incident occurs.
The choice between RDB and AOF is not mutually exclusive — combining both gives you fast disaster recovery via RDB snapshots AND minimal data loss via AOF logging. This is the configuration Redis itself recommends for production deployments, and it’s what we run for our own infrastructure. For advanced analytics on top of Redis data, tools like RedisSearch and RedisTimeSeries extend persistence into the analytics domain.
FAQ
Which persistence method should I use for Redis as a cache?
If data loss is acceptable (as with most caching use cases), disable both RDB and AOF entirely or use RDB with infrequent saves (save 3600 1). This maximizes performance since Redis never forks for snapshots or writes to the AOF. If you need cache warm-up after restart, RDB snapshots every few hours provide a reasonable starting dataset without significant performance impact.
Can I switch from RDB to AOF on a running instance?
Yes, without downtime:
| |
Redis will generate the initial AOF file in the background. The RDB file remains until you explicitly remove it. Note that this temporarily doubles disk usage until the AOF rewrite completes.
What happens if the AOF file gets corrupted?
Redis includes the redis-check-aof utility to repair truncated AOF files. If the last command was incompletely written (e.g., during a power failure), the tool can trim the file to the last valid command:
| |
For severely corrupted files, restore from the most recent RDB snapshot and replay the AOF from that point.
How much memory overhead does BGSAVE add?
BGSAVE uses Linux’s copy-on-write fork mechanism. The memory overhead depends on write activity during the save — every modified page requires a copy. Under heavy write loads during a BGSAVE, memory usage can temporarily double. The rule of thumb: ensure at least 50% free memory for the fork overhead on write-heavy instances (>10K ops/sec).
Can I use both RDB and AOF simultaneously?
Yes, and this is the recommended production configuration. When both are enabled, Redis uses the AOF on restart (since it’s more durable) but also maintains RDB snapshots for disaster recovery and replica synchronization. With Redis 7.0’s multi-part AOF, the AOF base file is already in RDB format, making this combination even more efficient.
How do I backup a very large Redis instance (100GB+)?
For large instances, BGSAVE can take minutes and consume significant memory for the fork. Strategies:
- Use a replica: Run BGSAVE on a read-replica to avoid impacting the primary
- AOF-based backup: Copy the AOF file while Redis is running (safe with appendfsync everysec)
- Incremental replication: Use Redis replication to maintain a hot standby, then backup from the standby
- Shard your data: Split across multiple Redis instances (Redis Cluster) to keep individual BGSAVE operations manageable (under 30 seconds each)
💰 想测试你的市场判断力?我用 Polymarket 做预测市场交易——这是全球最大的预测市场平台,从大选结果到加密货币监管,什么都可以押注。和赌博不同,这是真正的信息市场:你懂的信息越多,胜率越高。我靠预测科技事件的走向已经赚了不少。用我的邀请链接注册:Polymarket.com