Challenge - 5 Problems
Redis Expiry Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this Redis command sequence?
Consider the following Redis commands executed in order:
What will the
SET session:12345 user1EXPIRE session:12345 10TTL session:12345What will the
TTL command return immediately after setting the expiry?Redis
SET session:12345 user1 EXPIRE session:12345 10 TTL session:12345
Attempts:
2 left
💡 Hint
TTL returns the remaining time to live in seconds for a key with expiry.
✗ Incorrect
The EXPIRE command sets the key to expire in 10 seconds. TTL immediately after returns the remaining seconds, which is 10.
🧠 Conceptual
intermediate2:00remaining
Which Redis key expiry behavior is correct?
In Redis, what happens when a key with an expiry time reaches zero?
Attempts:
2 left
💡 Hint
Redis uses lazy expiration to save CPU resources.
✗ Incorrect
Redis deletes expired keys lazily when accessed or during periodic checks, not immediately at expiry time.
📝 Syntax
advanced2:00remaining
Which command correctly sets a key to expire in 5 minutes?
Choose the correct Redis command to set the key
cache:item to expire in 5 minutes.Attempts:
2 left
💡 Hint
SETEX sets a key with a value and expiry in seconds.
✗ Incorrect
SETEX requires the expiry time in seconds and the value. 5 minutes = 300 seconds.
❓ optimization
advanced2:00remaining
How to efficiently manage memory with many expiring keys?
You have millions of keys with expiry in Redis. Which approach optimizes memory and CPU usage best?
Attempts:
2 left
💡 Hint
Redis combines lazy and active expiration for efficiency.
✗ Incorrect
Redis uses active expiration cycles to proactively remove expired keys, reducing memory and CPU spikes.
🔧 Debug
expert2:00remaining
Why does this Redis key never expire?
A developer runs these commands:
But the TTL command returns
SET temp:data 100EXPIRE temp:data 60TTL temp:dataBut the TTL command returns
-1. What is the most likely cause?Attempts:
2 left
💡 Hint
Setting a key again removes its expiry unless set with SETEX or EXPIRE after.
✗ Incorrect
If a key is overwritten by SET after EXPIRE, the expiry is removed, so TTL returns -1.