The Redis HKEYS
command returns all fields in the hash stored at the specified key.
Syntax
The syntax goes like this:
HKEYS key
So all we do is pass the name of the key to the command.
Example
Suppose we set the following hash:
HSET customer firstname "Rob" lastname "Banks" age 37
Result:
(integer) 3
We can use HKEYS
to get all fields from that hash:
HKEYS customer
Result:
1) "firstname" 2) "lastname" 3) "age"
The result is an array reply containing the field names.
Non-Existent Keys
Running the command against a key that doesn’t exist results in an empty array being returned:
HKEYS nonexistentkey
Result:
(empty array)
Passing the Wrong Number of Arguments
Passing the wrong number of arguments results in an error:
HKEYS customer lastname
Result:
(error) ERR wrong number of arguments for 'hkeys' command