0
0
Redisquery~20 mins

Temporary data with TTL in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis TTL 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?
Given the commands below, what will be the output of the final GET command?
Redis
SET session:12345 user1
EXPIRE session:12345 5
GET session:12345
# Wait 6 seconds
GET session:12345
A"user1" then "user1"
Bnil then "user1"
C"user1" then nil
Dnil then nil
Attempts:
2 left
💡 Hint
Think about what EXPIRE does and how TTL affects key availability.
🧠 Conceptual
intermediate
1:30remaining
Which Redis command sets a key with a TTL in one atomic operation?
You want to store a temporary key that automatically expires after 10 seconds. Which command achieves this in one step?
APSETEX key 10000 value
B
SET key value
EXPIRE key 10
CSETEX key 10 value
DSET key value EX 10
Attempts:
2 left
💡 Hint
Look for the command that combines setting and expiration in one call.
📝 Syntax
advanced
1:30remaining
Identify the syntax error in this Redis command for setting TTL
Which option contains a syntax error when trying to set a key with a TTL of 30 seconds?
Redis
SET mykey myvalue EXPIRE 30
ASETEX mykey 30 myvalue
BSET mykey myvalue EXPIRE 30
CSET mykey myvalue PX 30000
DSET mykey myvalue EX 30
Attempts:
2 left
💡 Hint
Check the correct option keyword for expiration in the SET command.
optimization
advanced
1:30remaining
Best practice to update TTL without changing key value
You want to extend the TTL of an existing key without modifying its value. Which command is the best choice?
AEXPIRE key 60
BSET key value EX 60
CSETEX key 60 value
DPERSIST key
Attempts:
2 left
💡 Hint
Consider commands that only affect TTL without overwriting data.
🔧 Debug
expert
2:30remaining
Why does this Lua script fail to set TTL on a key in Redis?
Consider this Lua script run via EVAL: local key = KEYS[1] redis.call('EXPIRE', key, 10) redis.call('SET', key, 'temp') return redis.call('TTL', key) Why might the TTL returned be -1 (no expiration)?
AThe key is set without expiration because SET overwrites TTL
BThe EXPIRE command is ignored inside Lua scripts
CThe script runs too fast for TTL to apply
DThe key is overwritten after EXPIRE, removing TTL
Attempts:
2 left
💡 Hint
Think about the order of commands and how SET affects TTL.