Bird
Raised Fist0
Redisquery~20 mins

Eviction policies overview in Redis - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Redis Eviction Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Redis eviction policy: noeviction
What happens when Redis reaches its max memory limit and the eviction policy is set to noeviction?
ARedis increases its memory limit dynamically to accommodate new data.
BRedis removes the least recently used keys automatically to free memory.
CRedis removes random keys to free memory and continues accepting writes.
DRedis stops accepting writes and returns an error until memory is freed.
Attempts:
2 left
💡 Hint
Think about what 'no eviction' means for memory management.
❓ query_result
intermediate
2:00remaining
Result of keys removed with allkeys-lru policy
Assume Redis has maxmemory set and eviction policy allkeys-lru. The database contains keys with varying last access times. Which keys will Redis remove first when memory is full?
ARandom keys without considering access time or expiration.
BOnly keys with an expiration time that are closest to expiring.
CKeys that were accessed least recently, regardless of expiration.
DKeys that were added most recently to the database.
Attempts:
2 left
💡 Hint
LRU means 'Least Recently Used'.
📝 Syntax
advanced
2:00remaining
Correct Redis config command for volatile-lfu eviction
Which Redis configuration command correctly sets the eviction policy to volatile-lfu?
ACONFIG SET maxmemory-policy volatile-lfu
BCONFIG SET eviction-policy volatile-lfu
CSET maxmemory-policy volatile-lfu
DCONFIG GET maxmemory volatile-lfu
Attempts:
2 left
💡 Hint
Check the exact syntax for setting maxmemory policy in Redis.
❓ optimization
advanced
2:00remaining
Choosing eviction policy for frequently accessed keys with expiration
You have a Redis cache with many keys that have expiration times and are accessed frequently. You want to optimize memory usage by evicting keys that are least frequently used but only among keys with expiration set. Which eviction policy should you choose?
Aallkeys-lru
Bvolatile-lfu
Cvolatile-random
Dnoeviction
Attempts:
2 left
💡 Hint
Focus on eviction policies that consider frequency and expiration.
🔧 Debug
expert
2:00remaining
Why does Redis evict keys unexpectedly with allkeys-random?
A Redis instance is configured with maxmemory and eviction policy allkeys-random. Unexpectedly, keys that are still frequently accessed are being evicted. Why does this happen?
ABecause allkeys-random evicts keys randomly without considering usage or expiration.
BBecause Redis evicts keys based on least recently used order in allkeys-random.
CBecause the maxmemory setting is ignored when eviction policy is allkeys-random.
DBecause Redis evicts only expired keys first, ignoring the policy.
Attempts:
2 left
💡 Hint
Think about what 'random' means in eviction context.

Practice

(1/5)
1. What is the main purpose of eviction policies in Redis?
easy
A. To encrypt Redis data
B. To configure the network settings of Redis
C. To backup data automatically
D. To decide how Redis frees memory when it is full

Solution

  1. Step 1: Understand Redis memory management

    Redis uses eviction policies to manage memory when it reaches its limit.
  2. Step 2: Identify the role of eviction policies

    Eviction policies decide which data to remove to free memory and keep Redis running smoothly.
  3. Final Answer:

    To decide how Redis frees memory when it is full -> Option D
  4. Quick Check:

    Eviction policies control memory freeing = A [OK]
Hint: Eviction policies manage memory freeing in Redis [OK]
Common Mistakes:
  • Confusing eviction policies with backup or encryption
  • Thinking eviction policies configure network
  • Assuming eviction policies handle data encryption
2. Which command correctly sets the eviction policy to 'allkeys-lru' in Redis?
easy
A. CONFIG SET maxmemory-policy allkeys-lru
B. SET maxmemory-policy allkeys-lru
C. CONFIG GET maxmemory-policy allkeys-lru
D. EVICT POLICY allkeys-lru

Solution

  1. Step 1: Recall the correct command format

    Redis uses CONFIG SET to change configuration settings.
  2. Step 2: Match the correct syntax for eviction policy

    The correct syntax is CONFIG SET maxmemory-policy policy_name, so allkeys-lru fits here.
  3. Final Answer:

    CONFIG SET maxmemory-policy allkeys-lru -> Option A
  4. Quick Check:

    Use CONFIG SET for eviction policy = A [OK]
Hint: Use CONFIG SET maxmemory-policy to set eviction [OK]
Common Mistakes:
  • Using SET instead of CONFIG SET
  • Using CONFIG GET to set a value
  • Using a non-existent EVICT POLICY command
3. Given Redis is set with eviction policy volatile-lru and maxmemory is reached, which keys are eligible for eviction?
medium
A. All keys regardless of expiration
B. Only keys with an expiration set
C. Only keys without expiration
D. No keys are evicted automatically

Solution

  1. Step 1: Understand 'volatile-lru' policy meaning

    This policy evicts keys with expiration set using least recently used (LRU) order.
  2. Step 2: Identify which keys can be evicted

    Only keys that have an expiration time are considered for eviction under 'volatile-lru'. Keys without expiration stay safe.
  3. Final Answer:

    Only keys with an expiration set -> Option B
  4. Quick Check:

    volatile-lru evicts expiring keys = B [OK]
Hint: volatile-lru evicts only keys with expiration [OK]
Common Mistakes:
  • Thinking all keys are evicted
  • Confusing volatile-lru with allkeys-lru
  • Assuming no keys are evicted automatically
4. You set Redis eviction policy to noeviction but Redis still evicts keys when memory is full. What is the likely cause?
medium
A. The policy was not applied correctly or Redis was restarted without saving config
B. Redis always evicts keys regardless of policy
C. noeviction policy evicts keys randomly
D. Redis ignores eviction policies when maxmemory is set

Solution

  1. Step 1: Understand 'noeviction' policy behavior

    This policy prevents Redis from evicting keys automatically when memory is full.
  2. Step 2: Identify why eviction still happens

    If eviction occurs, likely the policy was not saved or applied properly, or Redis restarted without config persistence.
  3. Final Answer:

    The policy was not applied correctly or Redis was restarted without saving config -> Option A
  4. Quick Check:

    noeviction means no eviction unless misconfigured = C [OK]
Hint: Check config save and apply for noeviction policy [OK]
Common Mistakes:
  • Believing Redis always evicts keys
  • Thinking noeviction evicts randomly
  • Assuming eviction policies are ignored when maxmemory is set
5. You want Redis to evict the least recently used keys regardless of expiration when memory is full. Which eviction policy should you choose?
hard
A. volatile-lru
B. noeviction
C. allkeys-lru
D. volatile-random

Solution

  1. Step 1: Understand eviction policy options

    volatile-lru evicts only keys with expiration; allkeys-lru evicts any key using LRU.
  2. Step 2: Match requirement to policy

    Since eviction should ignore expiration and evict least recently used keys, allkeys-lru fits best.
  3. Final Answer:

    allkeys-lru -> Option C
  4. Quick Check:

    Evict any key LRU = allkeys-lru = D [OK]
Hint: allkeys-lru evicts any key by least recent use [OK]
Common Mistakes:
  • Choosing volatile-lru which only evicts expiring keys
  • Selecting volatile-random which evicts randomly
  • Picking noeviction which disables eviction
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard