0
0
Redisquery~20 mins

Embedding vs referencing in Redis - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Redis Embedding vs Referencing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Embedding in Redis
In Redis, embedding data means storing related information together in a single key. Which of the following best describes a scenario where embedding is beneficial?
AStoring large binary files separately and referencing them by file IDs.
BStoring user profiles in one key and their orders in separate keys linked by user IDs.
CUsing separate keys for each product and referencing them in a shopping cart key.
DStoring user profile details and their recent activity logs together in one hash for quick access.
Attempts:
2 left
💡 Hint
Think about when you want to access all related data quickly without multiple lookups.
🧠 Conceptual
intermediate
2:00remaining
When to Use Referencing in Redis
Referencing in Redis means storing related data separately and linking them by keys or IDs. Which situation is best suited for referencing?
AStoring product details separately and referencing them in multiple shopping carts.
BStoring a blog post and all its comments together in one hash.
CStoring all user data in one large JSON string.
DEmbedding all order details inside the user profile hash.
Attempts:
2 left
💡 Hint
Consider when data is shared or reused in multiple places.
query_result
advanced
2:00remaining
Result of Embedded Data Retrieval
Given a Redis hash key 'user:1000' storing embedded data: {"name":"Alice", "age":"30", "city":"NY"}, what is the output of the command: HGETALL user:1000 ?
Redis
HGETALL user:1000
A["user:1000", "Alice", "age", "30", "city", "NY"]
B["name", "Alice", "age", "30", "city", "NY"]
C["name", "Alice", "age", 30, "city", "NY"]
DError: key does not exist
Attempts:
2 left
💡 Hint
HGETALL returns all fields and values as strings in an array.
query_result
advanced
2:00remaining
Output of Referencing Data Retrieval
Assume you have two Redis keys: 'product:200' with value '{"name":"Book", "price":"15"}' and 'cart:300' storing a list of product IDs ['200', '201']. What is the output of LRANGE cart:300 0 -1 ?
Redis
LRANGE cart:300 0 -1
AError: wrong type operation on string
B[{"name":"Book", "price":"15"}, {"name":"Pen", "price":"5"}]
C["200", "201"]
D[]
Attempts:
2 left
💡 Hint
LRANGE returns elements of a list as stored, not the referenced data.
schema
expert
3:00remaining
Designing Redis Schema for Mixed Embedding and Referencing
You want to design a Redis schema for an e-commerce app where user profiles embed contact info but reference orders separately. Which schema design below correctly follows this approach?
AUser profile stored as hash 'user:ID' with fields 'name', 'email', 'phone'; orders stored as separate lists 'orders:ID' containing order IDs.
BUser profile stored as JSON string with embedded orders array inside; orders stored inside user hash fields.
COrders stored as hashes with user IDs embedded inside; user profiles stored as separate keys with no contact info.
DAll user data and orders embedded in one large hash 'user:ID' with nested fields for orders.
Attempts:
2 left
💡 Hint
Embedding contact info means storing it directly in user profile; referencing orders means separate keys.