0
0
Redisquery~20 mins

Hash vs string for objects in Redis - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Hash vs String Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why choose a Redis hash over a string for storing user profiles?

Consider you want to store user profile data in Redis. Which reason best explains why using a Redis hash is better than a single string for this?

AStrings automatically compress data, saving memory compared to hashes.
BHashes allow updating individual fields without rewriting the entire object.
CHashes can only store numeric values, making them faster than strings.
DStrings support nested data structures, while hashes do not.
Attempts:
2 left
💡 Hint

Think about how you update parts of a user profile frequently.

query_result
intermediate
2:00remaining
What is the output of this Redis command sequence?

Given these commands executed in order, what is the output of the final command?

HSET user:1 name "Alice" age "30"
HSET user:1 city "Paris"
HGETALL user:1
A["name", "Alice", "age", "30", "city", "Paris"]
B["user:1", "name", "Alice", "age", "30", "city", "Paris"]
CError: key user:1 does not exist
D["name", "Alice", "city", "Paris"]
Attempts:
2 left
💡 Hint

HGETALL returns all fields and values of a hash as a flat list.

📝 Syntax
advanced
2:00remaining
Which Redis command syntax correctly sets multiple fields in a hash?

Select the correct Redis command to set the fields 'name' to 'Bob' and 'age' to '25' in the hash 'user:2'.

AHMSET user:2 name Bob age 25
BSET user:2 name Bob age 25
CHSET user:2 {name: 'Bob', age: 25}
DHSET user:2 name Bob age 25
Attempts:
2 left
💡 Hint

Recent Redis versions recommend a specific command for setting multiple hash fields.

optimization
advanced
2:00remaining
Which approach is more memory efficient for storing 1000 small user objects in Redis?

You have 1000 user objects each with 5 small fields. Which Redis data structure is generally more memory efficient?

AStore each user as a separate Redis string with JSON data.
BStore all users in a single Redis list as JSON strings.
CStore each user as a Redis hash with 5 fields.
DStore each user as a Redis set with field values as members.
Attempts:
2 left
💡 Hint

Consider Redis internal encoding and overhead for small objects.

🔧 Debug
expert
2:00remaining
Why does this Redis command fail with a WRONGTYPE error?

Given the commands below, why does the last command produce a WRONGTYPE error?

SET user:3 "{\"name\":\"Eve\", \"age\": 28}"
HGET user:3 name
ABecause 'user:3' is a string key, not a hash, so HGET cannot be used.
BBecause the JSON string is invalid and cannot be parsed by HGET.
CBecause HGET requires the key to be a string, not a hash.
DBecause the field 'name' does not exist in the string value.
Attempts:
2 left
💡 Hint

Check the data type of the key before using hash commands.