HGETALL
The HGETALL
command in DiceDB is used to retrieve all the fields and values of a hash stored at a specified key. This command is particularly useful when you need to fetch the entire hash in one go, rather than fetching individual fields one by one.
Syntax
Parameters
Parameter | Description | Type | Required |
---|---|---|---|
key | The key of the hash from which you want to retrieve all fields and values. | String | Yes |
Return values
Condition | Return Value |
---|---|
The key exists and is a hash | Array of strings |
The key does not exist | Empty array |
Behaviour
When the HGETALL
command is executed:
- DiceDB checks if the specified key exists.
- If the key exists and is of type hash, DiceDB retrieves all the fields and their corresponding values.
- If the key does not exist, DiceDB returns an empty array.
- If the key exists but is not of type hash, an error is returned.
Errors
The HGETALL
command can raise the following errors:
-
Non-hash type or wrong data type
:- Error Message:
(error) WRONGTYPE Operation against a key holding the wrong kind of value
- Occurs if the key holds a non-hash data structure.
- Error Message:
-
Incorrect Argument Count
:- Error Message:
(error) ERR wrong number of arguments for 'hgetall' command
- Occurs if the command is not provided with the correct number of arguments (i.e., more than one).
- Error Message:
Example Usage
Retrieving all fields and values from an existing hash
Retrieving from a non-existing key
Error Example
Key is not a hash
Invalid number of arguments are passed