Hashes let you store multiple related fields (like name, age, email) under one key. This groups data logically and makes it easier to retrieve or update parts of the object without handling many separate keys.
HSET user:1 name "Alice" age "30" city "Paris"
HGETALL user:1
HSET user:1 name "Alice" age "30" city "Paris" HGETALL user:1
The HGETALL command returns all fields and their values stored in the hash as a flat list of alternating keys and values.
HSET product:100 name "Laptop" price 1200 stock 30
Redis commands do not use parentheses to group arguments. Option C incorrectly uses parentheses, causing a syntax error.
Using hashes groups related fields under one key, reducing overhead and allowing efficient access to individual fields without retrieving the entire object or multiple keys.
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?
The second HSET command lacks the hash key argument, so Redis treats 'age' as the key and '26' as the field, not updating the intended hash 'user:42'.