0
0
Redisquery~5 mins

HSET and HGET for fields in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Redis command HSET do?

HSET sets the value of a field in a hash stored at a key. If the field does not exist, it is created. If it exists, the value is updated.

Click to reveal answer
beginner
How do you retrieve the value of a specific field in a Redis hash?

You use the HGET command with the key and the field name to get the value stored in that field.

Click to reveal answer
beginner
What will HGET return if the field does not exist in the hash?

HGET returns null (or nil) if the specified field is not found in the hash.

Click to reveal answer
intermediate
Can HSET create a new hash if the key does not exist?

Yes, if the key does not exist, HSET will create a new hash and then set the field with the given value.

Click to reveal answer
intermediate
What is the difference between HSET and SET in Redis?

SET stores a simple string value at a key. HSET stores a field-value pair inside a hash at a key, allowing multiple fields under one key.

Click to reveal answer
What does the Redis command HGET myhash field1 return if field1 exists?
AThe key <code>myhash</code>
BThe value stored in <code>field1</code> inside <code>myhash</code>
CAn error message
DThe entire hash <code>myhash</code>
If you run HSET myhash field1 "hello" and field1 already has a value, what happens?
AThe value of <code>field1</code> is updated to "hello"
BA new field is created
CAn error is thrown
DNothing changes
What does HGET return if the field does not exist in the hash?
AAn empty string
B0
CThe entire hash
Dnull (nil)
Which command creates a new hash if the key does not exist?
AHSET
BHGET
CGET
DDEL
Which Redis command stores a simple string value at a key?
AHGET
BHSET
CSET
DHMSET
Explain how HSET and HGET work together to store and retrieve data in Redis hashes.
Think about how you store and look up information in a dictionary.
You got /4 concepts.
    Describe the difference between using SET and HSET in Redis.
    Compare storing one item versus storing a collection of items.
    You got /3 concepts.