Skip to content

Memory Limits and Eviction

maxmemory caps Redis memory usage. When the limit is reached, Redis applies the eviction policy to decide which keys to remove. You can set it in redis.conf or at runtime with CONFIG SET.

maxmemory 512mb
maxmemory-policy allkeys-lru
PolicyBehavior
noevictionReturn error on writes when full (default; safe for databases)
allkeys-lruEvict least recently used key from all keys
volatile-lruEvict LRU from keys with a TTL set
allkeys-lfuEvict least frequently used key from all keys
volatile-lfuEvict LFU from keys with a TTL
volatile-ttlEvict the key with the shortest remaining TTL
allkeys-randomEvict a random key from all keys
volatile-randomEvict a random key from keys with a TTL
127.0.0.1:6379> CONFIG GET maxmemory-policy
1) "maxmemory-policy"
2) "noeviction"
127.0.0.1:6379> CONFIG SET maxmemory-policy allkeys-lru
OK
127.0.0.1:6379> CONFIG GET maxmemory
1) "maxmemory"
2) "0"
127.0.0.1:6379> CONFIG SET maxmemory 256mb
OK
CONFIG GET maxmemory-policy
CONFIG SET maxmemory-policy allkeys-lru
CONFIG GET maxmemory
CONFIG SET maxmemory 256mb
Which eviction policy evicts the least recently used key from ALL keys?
What is the default eviction policy in Redis?
The `volatile-ttl` policy evicts keys based on what criterion?
Which command sets the eviction policy at runtime?