The Heroku Redis Maxmemory Policy
By Flavio Copes
Learn how the Heroku Redis maxmemory-policy setting controls eviction when memory fills up, compare options like allkeys-lru, and set it from the Heroku CLI.
Heroku’s Redis add-on is now called Heroku Key-Value Store. You still provision it as heroku-redis, and under the hood it runs Valkey, the open source fork of Redis. Heroku dropped its free plans in November 2022, so the cheapest tier today is Mini: 25 MB of memory for a maximum of $3/month (prices checked in September 2026). The next one, Premium 0, gives you 50 MB for $15/month.
25 MB fills up fast with a few thousand keys, depending on what you store.
Heroku has a configuration option called maxmemory-policy that determines how the system behaves when the instance memory is full.
By default this property is set to noeviction, which means the server raises an error when a client tries to store more data.
This is done so you realize what is happening. Once you find out that you can change this behavior, it’s time to determine how.
The policies come from Redis itself, and Valkey kept them. These are the ones Heroku lets you set:
noeviction: return errors when the memory limit was reached and the client is trying to execute commands that could result in more memory to be used (most write commands, but DEL and a few more exceptions).allkeys-lru: evict keys by trying to remove the less recently used (LRU) keys first, in order to make space for the new data added.volatile-lru: evict keys by trying to remove the less recently used (LRU) keys first, but only among keys that have an expire set, in order to make space for the new data added.allkeys-lfu: evict any key using approximated least-frequently-used (LFU).volatile-lfu: evict using approximated LFU, but only among keys that have an expire set.allkeys-random: evict keys randomly in order to make space for the new data added.volatile-random: evict keys randomly in order to make space for the new data added, but only evict keys with an expire set.volatile-ttl: evict keys with an expire set, and try to evict keys with a shorter time to live (TTL) first, in order to make space for the new data added.
It’s up to you to find the best case for your needs. For a plain cache, allkeys-lru is a good default. Once you have a candidate, apply the change using the Heroku CLI:
heroku redis:maxmemory YOUR_REDIS_INSTANCE_NAME --policy allkeys-lru -a your-app
If you skip -a, Heroku uses the current app from git remotes. The instance name is the add-on name from heroku redis:info (or heroku addons).
Want me to talk about your product? You can sponsor this site.