4. You run HGETALL user:2000 but get an empty list []. What could be the reason?
medium
A. HGETALL only returns keys, not values.
B. HGETALL command syntax is incorrect.
C. The hash key user:2000 does not exist or is empty.
D. Redis server is down.
Solution
Step 1: Interpret empty list from HGETALL
An empty list means the hash key does not exist or has no fields stored.
Step 2: Eliminate other options
Syntax error would cause an error message, server down would cause connection failure, and HGETALL returns both keys and values.
Final Answer:
The hash key user:2000 does not exist or is empty. -> Option C
Quick Check:
Empty list means no data for key [OK]
Hint: Empty list means key missing or hash empty [OK]
Common Mistakes:
Assuming syntax error without checking command
Thinking server down causes empty list
Believing HGETALL returns only keys
5. You want to display all user details stored in a Redis hash user:3000 as a JSON object in your application. Which approach correctly uses HGETALL and processes its output?
hard
A. Run HGETALL user:3000, then convert the returned flat list into key-value pairs to form a JSON object.
B. Run HGETALL user:3000 and directly use the returned list as JSON.
C. Run HGET user:3000 * to get all fields as JSON.
D. Run GET user:3000 to get the JSON string.
Solution
Step 1: Understand HGETALL output format
HGETALL returns a flat list alternating fields and values, not a JSON object.
Step 2: Convert flat list to JSON object
To use in an application, convert the list into key-value pairs (e.g., a dictionary) to form a JSON object.
Step 3: Eliminate incorrect options
Run HGETALL user:3000 and directly use the returned list as JSON. is wrong because the list is not JSON. Run HGET user:3000 * to get all fields as JSON. uses invalid syntax. Run GET user:3000 to get the JSON string. assumes the hash is stored as a string.
Final Answer:
Run HGETALL user:3000, then convert the returned flat list into key-value pairs to form a JSON object. -> Option A
Quick Check:
Convert HGETALL list to JSON object before use [OK]
Hint: Convert HGETALL list to key-value pairs for JSON [OK]
Common Mistakes:
Using HGET with wildcard which is invalid
Assuming HGETALL returns JSON directly
Using GET on a hash key expecting JSON
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.