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?
Other Common Redis Questions (and Answers)
Free System Design on AWS E-Book
Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.
Switch & save up to 80%
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost