0
0
Redisquery~5 mins

HKEYS and HVALS in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AThe number of fields in <code>myhash</code>
BAll field names in the hash stored at <code>myhash</code>
CAll values in the hash stored at <code>myhash</code>
DDeletes the hash <code>myhash</code>
What will HVALS myhash return if myhash has fields name and age with values "Bob" and 25?
A25
B["name", "age"]
C["Bob", "25"]
DAn error
What happens if you run HKEYS on a Redis string key?
AReturns all characters in the string
BDeletes the string
CReturns an empty list
DReturns an error
Which Redis command would you use to get all the values from a hash?
AHVALS
BHKEYS
CHGETALL
DHMGET
If a hash is empty, what does HKEYS return?
AEmpty list
BList with one empty string
CError
DNull
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.