Lorixen.
EN

Redis lost data after a restart? Choose RDB or AOF

Short answer: If Redis came back empty after a restart, persistence was probably switched off or only saving snapshots now and then. Redis offers two ways to keep data on disk: RDB snapshots at intervals and an append-only file (AOF) that logs every write. For data you can't lose, such as job queues, sessions or carts, turn on AOF with the everysec setting, which the Redis docs say risks about one second of data in a disaster. For a pure cache, no persistence is fine, as long as the app expects it.

Why Redis loses data

Redis keeps its whole dataset in memory, which is what makes it fast. Whether anything survives a restart depends entirely on its persistence settings. Depending on how Redis was installed, it may:

  • Save nothing at all, so every restart starts empty.
  • Save RDB snapshots occasionally, so a crash loses everything since the last snapshot.
  • Log writes with AOF, so very little is lost.

Teams often start using Redis as a cache, where losing data is harmless, and then quietly add jobs, sessions, rate-limit counters or shopping carts to it. The settings never change, and one day a server reboot logs every customer out or drops a queue of unsent emails.

The options, according to Redis

The Redis persistence documentation lists the choices:

  • RDB (Redis Database): point-in-time snapshots of your dataset at specified intervals.
  • AOF (Append Only File): logs every write operation the server receives; on startup, these are replayed to rebuild the dataset.
  • No persistence: disabled completely, sometimes used for caching.
  • RDB + AOF: both combined in the same instance.

Choosing for your data

Start by listing what your app stores in Redis and how bad it would be to lose each item.

Pure cache (rendered pages, API responses, computed results): no persistence or RDB only. If Redis empties, the app recomputes. Make sure it can handle a burst of cache misses after a restart.

Sessions and carts: losing them annoys customers but isn't catastrophic. RDB snapshots every few minutes may be acceptable; AOF with everysec is safer.

Job queues, scheduled tasks, counters that matter: treat these like real data. Use AOF, and consider whether the queue's critical state should live in your main database instead.

How AOF syncing works

AOF writes each change to a file, but the operating system decides when that file actually reaches the disk unless Redis forces it with fsync. The appendfsync setting controls this, and the docs describe three choices:

  • always: fsync after every write. Very slow, very safe.
  • everysec: fsync once a second. The docs call it fast enough and note you may lose one second of data in a disaster. This is the usual choice.
  • no: leave it to the operating system. Fastest, least safe.

AOF files grow over time. Redis rewrites them in the background to keep them compact, and modern versions handle this automatically, but it uses extra disk space and memory during the rewrite. Leave headroom on the server.

Checking what you have now

Ask your developer or hosting provider to check:

  1. The current settings. In redis-cli, CONFIG GET save shows RDB snapshot rules and CONFIG GET appendonly shows whether AOF is on.
  2. Where files are written. CONFIG GET dir shows the folder. If it's inside a container without a persistent volume, files vanish with the container, whatever the settings say.
  3. Whether settings are permanent. Changes made with CONFIG SET take effect immediately but may not survive a restart unless written to the config file (CONFIG REWRITE or editing redis.conf).
  4. Managed services. If you use a hosted Redis, persistence is usually a plan or instance option. Check what yours provides.

Making the change safely

  • Test on a copy first. Enable AOF on a staging instance and restart it to confirm data comes back.
  • Watch disk space and memory after enabling AOF, especially during rewrites.
  • Back up the persistence files. Persistence protects against restarts, not against deleted keys or a lost server. Copy RDB snapshots off the server regularly.
  • Restart and verify once in production at a quiet time, so you know the setup works before you need it.

Common mistakes

  • Assuming the default is safe. Defaults differ between packages, container images and hosting plans. Check the actual running instance rather than trusting what a tutorial said.
  • Turning on AOF but keeping the files on temporary storage. In containers and some cloud setups, the disk disappears with the instance. Persistence needs a persistent volume.
  • Mixing cache and critical data in one instance with a memory eviction policy that removes keys under pressure. If Redis is allowed to evict, your queue entries can vanish without any restart at all. Keep critical data in an instance that doesn't evict, or in a separate one.
  • Never testing a restart. The first real restart shouldn't be the test.

A worked example

Picture a hypothetical Cork events company whose ticketing app stored carts and a queue of confirmation emails in Redis. After a routine server update and reboot, carts were empty and a batch of confirmation emails was never sent. The Redis instance had no persistence and lived in a container without a volume. The developer moved Redis data to a persistent volume, enabled AOF with everysec, added a daily copy of the RDB snapshot to separate storage, and moved the email queue's sent/unsent status into the main database so it could be rebuilt if needed.

FAQ

Does persistence make Redis slower?

AOF with everysec has a small cost that most small apps won't notice. always is much slower.

Is RDB alone enough?

For caches and data you can rebuild, often yes. For anything you can't lose, a crash between snapshots loses everything since the last one.

Can I recover data after Redis restarted empty?

Only if a snapshot or AOF file exists somewhere. If persistence was off, the data is gone.

Should I keep important data in Redis at all?

It can work with proper persistence, but many teams keep the source of truth in their main database and use Redis for speed.

If your app relies on Redis and you're not sure what would survive a restart, ask us to look over the setup.

Sources

WhatsAppBook a call