Challenge - 5 Problems
Redis Hash 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 HMGET command?
Given the following Redis commands:
HMSET user:1 name "Alice" age "30" city "Paris"
HMGET user:1 name city
What is the output of the HMGET command?
HMSET user:1 name "Alice" age "30" city "Paris"
HMGET user:1 name city
What is the output of the HMGET command?
Redis
HMSET user:1 name "Alice" age "30" city "Paris" HMGET user:1 name city
Attempts:
2 left
💡 Hint
HMGET returns the values of the specified fields in the order requested.
✗ Incorrect
HMSET sets multiple fields in a hash. HMGET retrieves the values of the specified fields. Here, 'name' and 'city' fields are requested, so their values 'Alice' and 'Paris' are returned in a list.
📝 Syntax
intermediate1:30remaining
Which HMSET command is syntactically correct?
Choose the correct syntax for setting multiple fields in a Redis hash with HMSET for key 'user:2' with fields 'name' as 'Bob' and 'age' as '25'.
Attempts:
2 left
💡 Hint
HMSET expects key followed by field and value pairs separated by spaces.
✗ Incorrect
The correct syntax for HMSET is: HMSET key field1 value1 field2 value2 ... Option A follows this format exactly.
❓ optimization
advanced2:00remaining
Which approach is best to retrieve multiple fields efficiently?
You want to get the values of fields 'name', 'age', 'city', and 'email' from a Redis hash 'user:3'. Which command is the most efficient to retrieve all these fields at once?
Attempts:
2 left
💡 Hint
HMGET retrieves multiple specified fields in one command.
✗ Incorrect
HMGET is designed to get multiple fields in one call, making it more efficient than multiple HGET calls. HGETALL returns all fields but may return unnecessary data. GET is for string keys, not hashes.
🔧 Debug
advanced2:00remaining
Why does this HMGET command return null for one field?
Given these commands:
HMSET user:4 name "Eve" age "28"
HMGET user:4 name city
Why does the HMGET command return ["Eve", null]?
HMSET user:4 name "Eve" age "28"
HMGET user:4 name city
Why does the HMGET command return ["Eve", null]?
Redis
HMSET user:4 name "Eve" age "28" HMGET user:4 name city
Attempts:
2 left
💡 Hint
HMGET returns null for fields that do not exist in the hash.
✗ Incorrect
Since 'city' was never set in the hash 'user:4', HMGET returns null for that field while returning the value for 'name'.
🧠 Conceptual
expert2:30remaining
What is the main difference between HMSET and HSET in recent Redis versions?
Redis introduced HSET to replace HMSET. What is the key difference between HMSET and HSET when setting multiple fields in a hash?
Attempts:
2 left
💡 Hint
Check Redis documentation about HMSET deprecation and HSET enhancements.
✗ Incorrect
In recent Redis versions, HMSET is deprecated. HSET now supports setting multiple fields at once, making it the preferred command.