0
0
Redisquery~20 mins

Why hashes represent objects in Redis - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Hash Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why are hashes used to represent objects in Redis?
In Redis, hashes are often used to represent objects. Why is this approach beneficial compared to using simple strings for each attribute?
ABecause hashes allow grouping multiple fields and values under one key, making it easier to manage related data as a single object.
BBecause hashes automatically encrypt the data stored inside, providing security for objects.
CBecause hashes consume more memory than strings, which improves performance.
DBecause hashes store data in a sorted order, which strings cannot do.
Attempts:
2 left
💡 Hint
Think about how you would store a user profile with multiple details in Redis.
query_result
intermediate
2:00remaining
What does this Redis command output?
Given the following Redis commands executed in order, what is the output of the last command?

HSET user:1 name "Alice" age "30" city "Paris"
HGETALL user:1
Redis
HSET user:1 name "Alice" age "30" city "Paris"
HGETALL user:1
AError: HGETALL command not found
B["user:1", "name", "Alice", "age", "30", "city", "Paris"]
C["name", "Alice"]
D["name", "Alice", "age", "30", "city", "Paris"]
Attempts:
2 left
💡 Hint
HGETALL returns all fields and values in the hash as a list.
📝 Syntax
advanced
2:00remaining
Identify the syntax error in this Redis hash command
Which option contains a syntax error when trying to add fields to a Redis hash named 'product:100'?
Redis
HSET product:100 name "Laptop" price 1200 stock 30
AHSET product:100 name "Laptop" price 1200 stock 30
BHSET product:100 name "Laptop" price "1200" stock "30"
CHSET product:100 (name "Laptop" price 1200 stock 30)
DHSET product:100 name Laptop price 1200 stock 30
Attempts:
2 left
💡 Hint
Check the use of parentheses in Redis commands.
optimization
advanced
2:00remaining
Optimizing storage of user profiles in Redis
You want to store 10,000 user profiles in Redis. Each profile has 5 fields: name, email, age, city, and phone. Which approach is most efficient in terms of memory and access speed?
AStore each field of every user as a separate Redis string key, e.g., user:1:name, user:1:email, etc.
BStore each user profile as a Redis hash with one key per user containing all 5 fields.
CStore all user profiles in a single Redis list, each element a JSON string of the profile.
DStore user profiles as Redis sets with each field as a member.
Attempts:
2 left
💡 Hint
Consider grouping related data and efficient retrieval.
🔧 Debug
expert
2:00remaining
Why does this Redis hash command fail to update the field?
You run the following commands:

HSET user:42 name "Bob" age "25"
HSET age 26
HGET user:42 age

But the last command returns "25" instead of "26". What is the most likely reason?
AThe second HSET command is missing the hash key argument, so it does not update the intended hash.
BThe Redis server is caching the old value and did not update the field.
CThe second HSET command is missing quotes around the key, causing it to create a new key instead of updating.
DThe second HSET command is interpreted as setting a new key named 'age' instead of updating the hash.
Attempts:
2 left
💡 Hint
Check the number of arguments in the second HSET command.