Redis has a maxmemory-policy where it decides how to handle keys when memory limit is reached.
|will return errors when the memory limit is reached.
|will remove less recently used keys first.
|will remove less recently used keys first that have an expiry set.
|will evict random keys.
|will evict random keys but only those that have an expiry set.
|will only evict keys with an expiry set and a short TTL.
|will evict using approximated LFU among the keys with an expire set.
|will 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.