Redis HGETALL Command

The Redis HGETALL command returns all fields and values from the hash at the specified key.

Syntax

The syntax goes like this:

HGETALL 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 HGETALL to get all fields and values from that key:

HGETALL customer

Result:

1) "firstname"
2) "Rob"
3) "lastname"
4) "Banks"
5) "age"
6) "37"

The result is an array reply containing the fields and values in the hash.

Non-Existent Keys

Running the command against a key that doesn’t exist results in an empty array being returned:

HGETALL nonexistentkey

Result:

(empty array)

Passing the Wrong Number of Arguments

Passing the wrong number of arguments results in an error:

HGETALL customer lastname

Result:

(error) ERR wrong number of arguments for 'hgetall' command