0
0
Redisquery~20 mins

SET with expiry (EX, PX) in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Expiry Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this Redis command sequence?
Consider the following Redis commands executed in order:

SET mykey "Hello" EX 10
TTL mykey

What will the TTL mykey command return immediately after setting the key?
Redis
SET mykey "Hello" EX 10
TTL mykey
AAn integer close to 10 (e.g., 9 or 10)
B-1 (key exists but has no expiry)
C-2 (key does not exist)
DSyntax error
Attempts:
2 left
💡 Hint
EX sets the expiry time in seconds when setting the key.
query_result
intermediate
2:00remaining
What happens when you use PX with SET in Redis?
You run the command:

SET session "abc123" PX 5000

What does the PX 5000 option do?
Redis
SET session "abc123" PX 5000
ASets the key without expiry
BSets the key to expire after 5000 seconds
CSets the key to expire after 5000 milliseconds (5 seconds)
DCauses a syntax error
Attempts:
2 left
💡 Hint
PX sets expiry in milliseconds, EX sets expiry in seconds.
📝 Syntax
advanced
2:00remaining
Which SET command syntax is invalid in Redis?
Identify the invalid Redis SET command syntax among the options below:
ASET user "Alice" EX 20 PX 1000
BSET user "Alice" PX 1000
CSET user "Alice" EX 20
DSET user "Alice"
Attempts:
2 left
💡 Hint
You cannot use both EX and PX options together in one SET command.
query_result
advanced
2:00remaining
What is the result of this Redis command sequence?
Given the commands:

SET key1 "value1" EX 1
GET key1
WAIT 2000
GET key1

What will be the output of the second GET key1?
Redis
SET key1 "value1" EX 1
GET key1
WAIT 2000
GET key1
A"value1"
Bnil
CSyntax error
D"" (empty string)
Attempts:
2 left
💡 Hint
EX 1 sets expiry to 1 second, WAIT 2000 waits 2 seconds.
🧠 Conceptual
expert
2: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.
APX automatically renews the key expiry on access
BPX is faster to execute than EX
CPX stores expiry time as a timestamp instead of duration
DPX allows more precise expiry times for short-lived keys
Attempts:
2 left
💡 Hint
Think about the difference between seconds and milliseconds.