Recall & Review
beginner
What does the Redis command
HKEYS do?The
HKEYS command returns all the field names (keys) stored in a hash at a given key.Click to reveal answer
beginner
What does the Redis command
HVALS do?The
HVALS command returns all the values stored in a hash at a given key.Click to reveal answer
beginner
If a Redis hash has fields
name, age, and city, what will HKEYS return?It will return a list of the field names:
["name", "age", "city"].Click to reveal answer
beginner
If a Redis hash has values
"Alice", 30, and "NYC" for fields name, age, and city, what will HVALS return?It will return a list of the values:
["Alice", "30", "NYC"].Click to reveal answer
intermediate
Can
HKEYS and HVALS be used on a Redis key that is not a hash?No, both commands only work on keys holding hashes. Using them on other data types will cause an error.
Click to reveal answer
What does the Redis command
HKEYS myhash return?✗ Incorrect
HKEYS returns all the field names (keys) in the hash.What will
HVALS myhash return if myhash has fields name and age with values "Bob" and 25?✗ Incorrect
HVALS returns all values in the hash.What happens if you run
HKEYS on a Redis string key?✗ Incorrect
Using
HKEYS on a non-hash key causes an error.Which Redis command would you use to get all the values from a hash?
✗ Incorrect
HVALS returns all values from a hash.If a hash is empty, what does
HKEYS return?✗ Incorrect
HKEYS returns an empty list if the hash has no fields.Explain what the Redis commands
HKEYS and HVALS do and when you would use them.Think about how you get all keys or all values from a dictionary in programming.
You got /4 concepts.
Describe what happens if you use
HKEYS or HVALS on a Redis key that is not a hash.Consider the data type restrictions of Redis commands.
You got /3 concepts.