Introducing Dragonfly Cloud! Learn More

Question: What is the ElastiCache Redis eviction policy, and how can it be configured?

Answer

ElastiCache Redis eviction policy refers to the method that Redis uses to automatically remove data from your cache when the memory limit is reached, ensuring that new data can be written into the cache. There are several different eviction policies you can set in Redis:

  1. noeviction: The default policy. If memory limit is reached, Redis will return errors on write operations.
  2. allkeys-lru: Evict the least recently used (LRU) keys out of all keys.
  3. volatile-lru: Evict the least recently used (LRU) keys among keys that have an expire set.
  4. allkeys-random: Remove random keys out of all keys.
  5. volatile-random: Remove random keys among keys that have an expire set.
  6. volatile-ttl: Remove keys with the closest expiration time among keys that have an expire set.

To configure eviction policy in ElastiCache Redis, you need to modify the parameter group associated with your Redis instance. Here's how you might do this using AWS CLI:

aws elasticache modify-cache-parameter-group --cache-parameter-group-name my-group --parameter-name-value-list "ParameterName=maxmemory-policy,ParameterValue=allkeys-lru"

This command sets the eviction policy to allkeys-lru for the parameter group named my-group.

Please note that the choice of eviction policy can significantly impact the performance of your cache, so choose wisely based on specific use case.

Remember to apply the updated parameter group to your ElastiCache Redis cluster for changes to take effect. This change doesn't require a reboot, it will apply immediately.

For more details, please refer to the AWS documentation.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.