Redis Eviction events occur when the memory limit defined in your configuration (or default settings) is reached and newer data needs to be added. When this happens, Redis uses its eviction policy to evict existing keys to make room for new data.
There are several eviction policies that Redis supports:
To set a specific eviction policy, you can update Redis configuration file redis.conf
or use the CONFIG SET
command as follows:
redis-cli CONFIG SET maxmemory-policy allkeys-lru
The choice of eviction policy greatly depends on what kind of data you're storing in Redis and how critical it is to preserve certain types of data over others.
You can monitor eviction events using Redis's INFO
command. The evicted_keys
field in the output shows the number of keys that have been evicted due to max memory limit:
redis-cli INFO
In the output, look for:
# Memory used_memory:832592 used_memory_human:813.07K used_memory_rss:9850880 used_memory_peak:842176 used_memory_peak_human:822.34K used_memory_lua:37888 mem_fragmentation_ratio:11.83 mem_allocator:jemalloc-3.6.0 evicted_keys:1000
Here, evicted_keys
indicates the total keys evicted due to max memory limit.
By understanding Redis eviction events and setting appropriate eviction policies, you can efficiently manage your memory usage in Redis.
Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.