Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Redis · Command

HGETALL

Returns every field and value in the hash stored at a key. The operation is O(N), where N is the number of fields.

Since
2.0.0

How it works

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.

Syntax

HGETALL key

Parameters

NameTypeDescription
keykeyThe name of the key that holds the hash.

Returns

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.

Key points

  • It retrieves the complete contents of the hash identified by key.
  • The returned sequence alternates each field name with that field's value.
  • Execution cost grows linearly with the number of fields in the hash.
  • The only required argument is the key containing the target hash.
  • The command is categorized as a hash read operation with slow, size-dependent work.

Common mistakes

  • The raw Redis reply is a flat sequence, not alternating nested field-value objects; its element count is twice the number of fields.

Example: Read a complete hash

HSET user:42 name Ada language Redis
HGETALL user:42

Creates a hash and returns its complete field-value mapping.

When to use it

Inspect a hash

A diagnostic or administration tool needs to display the complete contents of a hash.

Load a complete cached record

An application needs to materialize all attributes associated with one cached entity.

Export hash contents

A migration or synchronization job must enumerate every field-value pair for a hash.

Interview questions

QWhat does HGETALL return and what is its complexity?

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.

QWhat is the command syntax and role of key?

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.

QWhen was HGETALL introduced, and how does its cost scale?

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.

  • HGET
  • HSET
  • HMGET
  • HSCAN

Source: HGETALL | Docs - Redis. Checked 2026-10-16.