/

The Heroku Redis Maxmemory Policy

The Heroku Redis Maxmemory Policy

Heroku offers a powerful Redis addon that comes with 25MB of free memory storage. But what happens when you exceed this limit? Heroku has a configuration option called maxmemory-policy that determines how the system handles the situation.

By default, the maxmemory-policy is set to noeviction, which means that if you try to store more data than the available memory, Redis will raise an error. This is done to notify you of the issue and prompt you to take action.

Fortunately, Redis provides a number of different behaviors to handle memory overflow. Here are the available options:

  1. noeviction: Redis returns errors when the memory limit is reached and the client attempts to execute commands that would require more memory.
  2. allkeys-lru: Redis evicts the least recently used (LRU) keys to free up memory for new data.
  3. volatile-lru: Similar to allkeys-lru, Redis evicts LRU keys but only among keys that have an expiration set.
  4. allkeys-random: Redis randomly evicts keys to make space for new data.
  5. volatile-random: Similar to allkeys-random, Redis randomly evicts keys but only those with an expiration set.
  6. volatile-ttl: Redis evicts keys with an expiration set, giving priority to keys with a shorter time to live (TTL).

Choosing the right maxmemory-policy depends on your specific needs and application requirements. Once you have determined the most suitable policy, you can apply the change using the Heroku CLI. For example:

1
heroku redis:maxmemory YOUR_REDIS_INSTANCE_NAME --policy volatile-lru

By adjusting the maxmemory-policy, you can ensure optimal memory usage and prevent data loss in your Heroku Redis instance.

tags: [“Heroku”, “Redis”, “maxmemory-policy”, “memory overflow”, “memory management”]