0
0
Redisquery~20 mins

Eviction policies (LRU, LFU, random) in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Eviction Policy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What happens when Redis uses the LRU eviction policy?

Redis is configured with the allkeys-lru eviction policy and maxmemory is reached. Which keys are removed first?

AKeys with the largest size in memory are removed first.
BKeys are removed randomly without considering usage.
CKeys that were least recently accessed are removed first.
DKeys that were least frequently accessed are removed first.
Attempts:
2 left
💡 Hint

Think about what 'LRU' stands for in cache eviction.

query_result
intermediate
2:00remaining
How does the LFU eviction policy decide which keys to remove?

Redis is set to allkeys-lfu eviction policy. When memory is full, which keys get evicted?

AKeys with the oldest creation time are removed first.
BKeys that were least recently accessed are removed first.
CKeys are removed randomly without considering usage.
DKeys that were least frequently accessed are removed first.
Attempts:
2 left
💡 Hint

LFU stands for a frequency-based eviction.

📝 Syntax
advanced
2:00remaining
Which Redis configuration line correctly sets the eviction policy to random?

Choose the correct Redis config line to set eviction policy to allkeys-random.

Amaxmemory-policy random
Bmaxmemory-policy allkeys-random
Cmaxmemory-policy allkeys_random
Dmaxmemory-policy random-allkeys
Attempts:
2 left
💡 Hint

Check the exact spelling and format of Redis eviction policies.

🧠 Conceptual
advanced
2:00remaining
Why might LFU eviction be less efficient than LRU in some Redis workloads?

Consider Redis workloads with many keys accessed only once. Why could LFU eviction cause problems compared to LRU?

ALFU may keep rarely accessed keys longer because their frequency counters don't decay quickly.
BLFU removes keys randomly, causing unpredictable cache misses.
CLFU evicts keys based on size, which can remove important small keys.
DLFU requires more CPU, so Redis crashes under heavy load.
Attempts:
2 left
💡 Hint

Think about how frequency counters behave over time.

🔧 Debug
expert
2:00remaining
What error occurs if you set an invalid eviction policy in Redis config?

You add maxmemory-policy allkeys-lrux to your Redis config and restart. What happens?

ARedis starts but ignores the invalid policy and uses no eviction.
BRedis fails to start and shows a configuration error.
CRedis starts and uses the default LRU eviction policy silently.
DRedis starts but crashes when memory limit is reached.
Attempts:
2 left
💡 Hint

Invalid config options usually cause startup errors.