Hash commands
These are the commands that are available for the hash data type.
HSET <key> <field> <value> [field value ...]
Set the value of a field in a hash. Create a hash if it doesn't exist. Replace the value if the field already exists.
Example
> HSET hash field value another_field another_value
ok
> HSET hash new_field new_value
ok
HGET <key> <field>
Get the value of a field in a hash. Return nothing if the field doesn't exist.
Example
# Field exists
> HGET hash field
value
# Field doesn't exist
> HGET hash doesnt_exist
HGETALL <key>
Get all fields and values in a hash.
Example
> HGETALL hash
field
value
another_field
another_value
new_field
new_value
HDEL <key> <field>
Delete a field in a hash.
Example
> HDEL hash new_field
ok
HLEN <key>
Get the number of fields in a hash.
Example
> HLEN hash
2
HEXISTS <key> <field>
Check if a field exists in a hash.
Example
# Field exists
> HEXISTS hash field
1
# Field doesn't exist
> HEXISTS hash doesnt_exist
0
HKEYS <key>
Get all fields in a hash.
Example
> HKEYS hash
field
another_field
HVALS <key>
Get all values in a hash.
Example
> HVALS hash
value
another_value
Last updated on April 25, 2023