Challenge - 5 Problems
Redis Hash Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate1:30remaining
Retrieve a field from a Redis hash
Given a Redis hash stored with key
user:1001 containing fields name, email, and age, what is the output of the command HGET user:1001 email if the stored email is alice@example.com?Redis
HSET user:1001 name Alice email alice@example.com age 30 HGET user:1001 email
Attempts:
2 left
💡 Hint
Remember that HGET returns the value of the specified field in the hash.
✗ Incorrect
The HGET command fetches the value of the given field from the hash stored at the key. Since the field is 'email', it returns the stored email string.
📝 Syntax
intermediate1:30remaining
Identify the correct Redis command to add multiple fields to a hash
Which of the following commands correctly adds multiple fields
title and author to a Redis hash with key book:1?Attempts:
2 left
💡 Hint
Use the modern command that supports multiple field-value pairs.
✗ Incorrect
The HSET command in modern Redis versions supports multiple field-value pairs. HMSET is deprecated, HADD does not exist, and the syntax with curly braces is invalid.
❓ optimization
advanced2:00remaining
Efficiently retrieving multiple fields from a Redis hash
You want to retrieve the fields
name, email, and age from a Redis hash user:1002. Which command is the most efficient to get all three fields in a single call?Attempts:
2 left
💡 Hint
Choose the command that fetches specific fields in one request.
✗ Incorrect
HMGET fetches specified fields in one command efficiently. HGETALL returns all fields which may be unnecessary. Multiple HGET calls are less efficient. GET is for strings, not hashes.
🔧 Debug
advanced1:30remaining
Identify the error in this Redis hash command
What error will the following Redis command produce?
HSET user:1003 name "Bob" age
Redis
HSET user:1003 name "Bob" age
Attempts:
2 left
💡 Hint
HSET requires field-value pairs; check if all pairs are complete.
✗ Incorrect
HSET expects pairs of field and value. Here, 'age' is given without a value, causing a syntax error due to wrong number of arguments.
🧠 Conceptual
expert2:30remaining
Understanding Redis hash memory efficiency
Why are Redis hashes considered memory efficient for storing many small objects compared to storing each object as a separate key?
Attempts:
2 left
💡 Hint
Think about how Redis stores small hashes internally.
✗ Incorrect
Redis uses a special encoding (ziplist or listpack) for small hashes that packs fields tightly, reducing memory overhead compared to many separate keys.