0
0
Redisquery~20 mins

SET and GET commands in Redis - Practice Problems & Coding Challenges

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

SET user:1 "Alice"
GET user:1

What will the GET command return?
Redis
SET user:1 "Alice"
GET user:1
A"Alice"
Buser:1
Cnil
DError: key not found
Attempts:
2 left
💡 Hint
The SET command stores a value for a key. GET retrieves that value.
query_result
intermediate
1:00remaining
What happens when you GET a non-existing key?
If you run the command GET missing_key on Redis where no such key exists, what is the output?
Redis
GET missing_key
A(nil)
B"missing_key"
CError: key not found
D""
Attempts:
2 left
💡 Hint
Redis returns a special value when keys are missing.
📝 Syntax
advanced
1:30remaining
Which command syntax correctly sets a key with expiration of 10 seconds?
You want to set key "session" with value "xyz" that expires after 10 seconds. Which command is correct?
ASET session xyz PX 10
BSET session xyz TTL 10
CSET session xyz EXPIRE 10
DSET session xyz EX 10
Attempts:
2 left
💡 Hint
EX sets expiration in seconds, PX in milliseconds.
query_result
advanced
1:30remaining
What is the output after overwriting a key?
Given these commands:

SET color "red"
SET color "blue"
GET color

What does the GET command return?
Redis
SET color "red"
SET color "blue"
GET color
Anil
B"red"
C"blue"
DError: key already exists
Attempts:
2 left
💡 Hint
SET overwrites existing keys with new values.
🧠 Conceptual
expert
2:00remaining
Why does GET return nil after key expiration?
You set a key with expiration using SET key value EX 5. After 6 seconds, you run GET key. Why does it return nil?
AGET command cannot retrieve keys with expiration set.
BThe key automatically deletes after expiration time, so GET finds no key.
CRedis caches old values and returns nil if cache expires.
DThe key value is hidden but still exists, GET returns nil by design.
Attempts:
2 left
💡 Hint
Expiration removes the key from the database.