Inspect a hash
A diagnostic or administration tool needs to display the complete contents of a hash.
Redis · Command
Returns every field and value in the hash stored at a key. The operation is O(N), where N is the number of fields.
HGETALL reads the hash stored at the specified key and returns every field together with its value. The response represents each field immediately followed by its value, so the flat reply contains twice as many elements as the hash has fields.
HGETALL key| Name | Type | Description |
|---|---|---|
key | key | The name of the key that holds the hash. |
An array containing all field names and values in the hash; each field is followed by its value. If the hash is empty or the key does not exist, the result is empty.
HSET user:42 name Ada language Redis
HGETALL user:42Creates a hash and returns its complete field-value mapping.
A diagnostic or administration tool needs to display the complete contents of a hash.
An application needs to materialize all attributes associated with one cached entity.
A migration or synchronization job must enumerate every field-value pair for a hash.
HGETALL takes one key and returns all fields and values in the hash stored there. Its time complexity is O(N), where N is the hash size.
Follow-up: When should a client avoid it for a large hash? Use field-specific reads such as HMGET when only a subset is needed, because HGETALL processes every field.
The command syntax is HGETALL key. The key identifies the hash whose complete contents Redis should return.
Follow-up: What happens when the key does not hold a hash? Redis reports a wrong-type error rather than treating another data type as a hash.
HGETALL was introduced in Redis 2.0.0. It is a read operation for hashes and is classified as a slow command because its work scales with the number of fields.
Follow-up: How can an application reduce work when it needs selected fields? Issue HMGET with the required field names instead of retrieving the complete hash.
HGETHSETHMGETHSCAN