Challenge - 5 Problems
Denormalization Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this Redis command sequence?
Given these Redis commands executed in order:
1.
2.
3.
4.
What will be the combined output of commands 3 and 4?
1.
HSET user:1000 name "Alice" age 302.
HSET user:1000:profile city "New York" country "USA"3.
HMGET user:1000 name age4.
HMGET user:1000:profile city countryWhat will be the combined output of commands 3 and 4?
Redis
HSET user:1000 name "Alice" age 30 HSET user:1000:profile city "New York" country "USA" HMGET user:1000 name age HMGET user:1000:profile city country
Attempts:
2 left
💡 Hint
Remember that HMGET returns the values of the specified fields in the hash.
✗ Incorrect
The first HMGET fetches the 'name' and 'age' fields from 'user:1000' hash, which were set to 'Alice' and 30 respectively. The second HMGET fetches 'city' and 'country' from 'user:1000:profile' hash, set to 'New York' and 'USA'.
🧠 Conceptual
intermediate1:30remaining
Why is denormalization used in Redis for speed?
Which of the following best explains why denormalization is commonly used in Redis to improve speed?
Attempts:
2 left
💡 Hint
Think about how Redis handles data and what it lacks compared to relational databases.
✗ Incorrect
Redis does not support joins like relational databases. Denormalization stores related data together to reduce the number of queries and speed up data retrieval.
📝 Syntax
advanced2:00remaining
Which Redis command syntax correctly denormalizes user and order data?
You want to store user data and their latest order details together in Redis for fast access. Which command correctly sets a hash with user info and embedded order info?
Attempts:
2 left
💡 Hint
Redis hashes store flat field-value pairs; nested objects require flattening.
✗ Incorrect
Option A correctly uses HSET with flat field-value pairs including order info as separate fields. Option A tries to store a nested object which Redis does not support natively in hashes.
❓ optimization
advanced2:30remaining
How to optimize read speed with denormalized data in Redis?
You have user profiles and their recent activity logs stored separately. To optimize read speed for a dashboard showing both, what is the best denormalization strategy?
Attempts:
2 left
💡 Hint
Denormalization means combining related data to reduce queries.
✗ Incorrect
Combining user profile and recent activity in one hash reduces the number of Redis calls, improving read speed for dashboards.
🔧 Debug
expert3:00remaining
Why does this denormalized Redis data retrieval fail?
You stored denormalized user data with order info as:
But this command returns null:
Why?
HSET user:3000 name "Carol" age 40 order_id 5678 order_total 150.00But this command returns null:
HMGET user:3000 orderWhy?
Attempts:
2 left
💡 Hint
Check the exact field names stored in the hash.
✗ Incorrect
The hash has fields 'order_id' and 'order_total', but no field named 'order'. HMGET 'order' returns null because that field does not exist.