Question: How can you check the eviction policy in Redis?

Answer

In Redis, the eviction policy dictates how keys are removed when the database reaches its maximum memory limit. To check the current eviction policy, you can use the CONFIG GET command with the argument maxmemory-policy.

Here's an example of how to do this from a Redis client:

127.0.0.1:6379> CONFIG GET maxmemory-policy 1) "maxmemory-policy" 2) "allkeys-lru"

This command will return the currently set eviction policy along with the policy name. The possible eviction policies are:

  • 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.
  • allkeys-lru: Evict any key using the LRU algorithm when the memory limit is reached.
  • volatile-lru: Evict keys with an expire set using the LRU algorithm when the memory limit is reached.
  • allkeys-random: Evict any key randomly when the memory limit is reached.
  • volatile-random: Evict keys with an expire set randomly when the memory limit is reached.
  • volatile-ttl: Evict keys with an expire set and with the shortest time-to-live (TTL) first when the memory limit is reached.

Each of these policies has their own trade-offs, so it's important to select one that fits your application's needs.

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.