How to Disable Redis Persistence on Heroku Key-Value Store

When using Heroku Redis, you might notice that your Redis instance is configured with persistence enabled by default — specifically using AOF (Append Only File). This means that Redis writes every change to disk, so data is saved even after restarts. This is a great feature for most use cases — but not always necessary.

For example, if you’re using Redis only for caching, you might prefer to disable persistence completely for better performance and faster restarts. But can you actually do that on Heroku?

Let’s break it down.


What is Redis Persistence?

Redis has two main persistence methods:

  • RDB (Snapshotting): Saves the state of Redis at intervals.
  • AOF (Append Only File): Logs every write operation to disk.

Heroku uses AOF persistence for reliability. You can check this by running:

heroku redis:info -a your-app-name

You’ll see something like:

Persistence: AOF

Why You Can’t Disable Redis Persistence on Heroku

Unfortunately, you cannot disable persistence (AOF or RDB) on Heroku Redis. Heroku manages the Redis instance for you, and locks down administrative commands such as:

  • CONFIG GET
  • CONFIG SET
  • SAVE
  • BGSAVE
  • BGREWRITEAOF

These commands are blocked to prevent accidental misconfiguration or performance degradation in shared environments.

So if you try to run:

redis-cli -a your_redis_password -h your_redis_host CONFIG SET appendonly no

You’ll get an error like:

(error) ERR unknown command `CONFIG`

What Can You Do Instead?

Even though you can’t disable persistence, here’s what you can do if you’re using Redis for non-critical, cache-only purposes:

1. Let it Rebuild on Restart

Since you’re caching, it’s okay if Redis flushes all data on restart. Redis will come back empty, and your app can repopulate the cache naturally.

2. Use Short TTLs

Set a short expiry time (TTL) for your cached keys:

redisTemplate.expire("myKey", 10, TimeUnit.MINUTES);

This ensures your data doesn’t live too long and keeps memory usage low.

3. Avoid Storing Persistent Data

Only store data that your app can easily regenerate. Don’t rely on Redis to hold user sessions, critical transactions, or primary data if you’re not using its persistence features.

4. Consider an External Redis Provider

If you absolutely need to control persistence settings (e.g., turn it off), you might consider using an external Redis provider (like Redis Labs or AWS ElastiCache) that gives you full admin control.


Summary

Question Answer
Can I disable Redis persistence on Heroku? No, it’s managed and locked down
What persistence is used? AOF (Append Only File)
Can I run CONFIG commands? No, restricted on Heroku Redis
What’s the workaround? Use Redis as an ephemeral cache with short TTLs and allow data loss on restart

Final Thoughts

Heroku Redis is designed to be simple, reliable, and scalable — and that comes with some trade-offs, like restricted configuration access. If you’re using it purely for cache and don’t care about data after a restart, you can safely ignore the persistence settings and let your app repopulate the cache as needed.

If you ever need more control, that’s when a self-managed or third-party Redis setup might be the better fit.
#wwebhub

1 Like