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 mykey "Hello" EX 10TTL mykeyWhat will the
TTL mykey command return immediately after setting the key?Redis
SET mykey "Hello" EX 10 TTL mykey
Attempts:
2 left
💡 Hint
EX sets the expiry time in seconds when setting the key.
✗ Incorrect
The SET command with EX 10 sets the key to expire in 10 seconds. TTL returns the remaining time to live in seconds, so it will be close to 10 immediately after setting.
❓ query_result
intermediate2:00remaining
What happens when you use PX with SET in Redis?
You run the command:
What does the PX 5000 option do?
SET session "abc123" PX 5000What does the PX 5000 option do?
Redis
SET session "abc123" PX 5000
Attempts:
2 left
💡 Hint
PX sets expiry in milliseconds, EX sets expiry in seconds.
✗ Incorrect
PX option sets the expiry time in milliseconds. PX 5000 means the key expires after 5 seconds.
📝 Syntax
advanced2:00remaining
Which SET command syntax is invalid in Redis?
Identify the invalid Redis SET command syntax among the options below:
Attempts:
2 left
💡 Hint
You cannot use both EX and PX options together in one SET command.
✗ Incorrect
Using both EX and PX options together in a single SET command is invalid and causes a syntax error.
❓ query_result
advanced2:00remaining
What is the result of this Redis command sequence?
Given the commands:
What will be the output of the second
SET key1 "value1" EX 1GET key1WAIT 2000GET key1What will be the output of the second
GET key1?Redis
SET key1 "value1" EX 1 GET key1 WAIT 2000 GET key1
Attempts:
2 left
💡 Hint
EX 1 sets expiry to 1 second, WAIT 2000 waits 2 seconds.
✗ Incorrect
The key expires after 1 second. After waiting 2 seconds, the key no longer exists, so GET returns nil.
🧠 Conceptual
expert2:00remaining
Why might you prefer PX over EX when setting expiry in Redis?
Choose the best reason why a developer might choose PX (milliseconds) instead of EX (seconds) when using the SET command with expiry.
Attempts:
2 left
💡 Hint
Think about the difference between seconds and milliseconds.
✗ Incorrect
PX sets expiry in milliseconds, allowing finer control over expiry times, especially for very short durations.