0
0
Redisquery~20 mins

HSET and HGET for fields in Redis - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Hash 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:

HSET user:1 name "Alice" age 30
HGET user:1 name

What will be the output of the HGET command?
Redis
HSET user:1 name "Alice" age 30
HGET user:1 name
AAlice
Bnil
C30
DError: wrong type
Attempts:
2 left
💡 Hint
HSET stores fields and values in a hash. HGET retrieves the value of a given field.
query_result
intermediate
1:30remaining
What happens if you HGET a non-existing field?
Given the hash key user:2 with fields:
HSET user:2 name "Bob"

What is the result of:
HGET user:2 age?
Redis
HSET user:2 name "Bob"
HGET user:2 age
Anil
B"" (empty string)
C0
DError: field not found
Attempts:
2 left
💡 Hint
HGET returns nil if the field does not exist in the hash.
📝 Syntax
advanced
1:30remaining
Which command correctly sets multiple fields in a hash?
You want to set the fields 'name' to 'Carol' and 'age' to 25 in the hash 'user:3'. Which command is correct?
AHSET user:3 (name, Carol, age, 25)
BHSET user:3 name Carol age 25
CHSET user:3 [name, Carol, age, 25]
DHSET user:3 {name: Carol, age: 25}
Attempts:
2 left
💡 Hint
HSET takes the key followed by field and value pairs as separate arguments.
optimization
advanced
2:00remaining
Which approach is more efficient to update multiple fields in a Redis hash?
You need to update 5 fields in a Redis hash. Which is the best approach?
AUse HGET to get all fields, modify locally, then HSET all fields again
BUse 5 separate HSET commands, one per field
CUse one HSET command with all 5 field-value pairs at once
DUse multiple HGET commands, one per field, then HSET for each
Attempts:
2 left
💡 Hint
Minimizing the number of commands sent to Redis improves performance.
🧠 Conceptual
expert
2:00remaining
What is the result of this Redis command sequence?
Given the commands:
HSET user:4 name "Dave" age 40
HSET user:4 age 41
HGET user:4 age

What is the output of the last command?
Redis
HSET user:4 name "Dave" age 40
HSET user:4 age 41
HGET user:4 age
A"40"
BError: field not found
Cnil
D"41"
Attempts:
2 left
💡 Hint
HSET overwrites existing fields with new values.