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?
Think about how you update parts of a user profile frequently.
Redis hashes let you update or retrieve individual fields without rewriting the whole object, which is efficient for partial updates. Strings require rewriting the entire value.
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
HGETALL returns all fields and values of a hash as a flat list.
HGETALL returns all fields and values in the hash as a list of alternating keys and values.
Select the correct Redis command to set the fields 'name' to 'Bob' and 'age' to '25' in the hash 'user:2'.
Recent Redis versions recommend a specific command for setting multiple hash fields.
HSET supports multiple field-value pairs in recent Redis versions. HMSET is deprecated. SET is for strings, not hashes. Option D is invalid syntax.
You have 1000 user objects each with 5 small fields. Which Redis data structure is generally more memory efficient?
Consider Redis internal encoding and overhead for small objects.
Redis hashes are optimized for small objects and use less memory than storing JSON strings in separate keys or lists. Sets are not suitable for key-value pairs.
Given the commands below, why does the last command produce a WRONGTYPE error?
SET user:3 "{\"name\":\"Eve\", \"age\": 28}"
HGET user:3 nameCheck the data type of the key before using hash commands.
HGET only works on hash keys. Here, 'user:3' is a string key, so using HGET causes a WRONGTYPE error.