Heroku Redis Key Eviction Policy

Redis has a maxmemory-policy where it decides how to handle keys when memory limit is reached.

noevictionwill return errors when the memory limit is reached.
allkeys-lruwill remove less recently used keys first.
volatile-lruwill remove less recently used keys first that have an expiry set.
allkeys-randomwill evict random keys.
volatile-randomwill evict random keys but only those that have an expiry set.
volatile-ttlwill only evict keys with an expiry set and a short TTL.
volatile-lfuwill evict using approximated LFU among the keys with an expire set.
allkeys-lfuwill evict any key using approximated LFU.

Here is how to change the maxmemory-policy on Heroku, with heroku-cli.

$ heroku redis:maxmemory <redis-instance-name> --policy allkeys-lru --app <app-name>

You should receive the message:

Maxmemory policy for redis-xxx-xxxx (REDIS_URL) set to allkeys-lru.
allkeys-lru evict keys trying to remove the less recently used keys first.

Leave a Comment