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

This command will return the currently set eviction policy. 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?

Start building today

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