w3resource

Redis Hash: HGETALL

Redis HGETALL Command

Redis HGETALL command is used to get all fields and values of the hash stored at key. In the returned value, every field name is followed by its value, so the length of the reply is twice the size of the hash.

Here are some common uses and scenarios for the "HGETALL" command:

  • Complete Hash Retrieval: Fetch all field-value pairs in a hash.
  • Data Inspection: Inspect the entire content of a hash for debugging or analysis.
  • Configuration Management: Retrieve all configuration settings stored in a hash.
  • Session Management: Access all attributes or data associated with a session or user.
  • Data Migration: Export entire hash data for migration or backup purposes.

Syntax:

HGETALL KEY_NAME 

Available since

2.0.0.

Return Value

Array reply, a list of fields and their values stored in the hash, or an empty list when a key does not exist.

Return Value Type

Integer

Example: Redis HGETALL

127.0.0.1:6379> HMSET langhash lang1 "PHP" lang2 "JavaScript" lang3 "Python"
OK
127.0.0.1:6379> HSET langhash lang4 "Golanguage"
(integer) 1
127.0.0.1:6379> HGETALL langhash
1) "lang1"
2) "PHP"
3) "lang2"
4) "JavaScript"
5) "lang3"
6) "Python"
7) "lang4"
8) "Golanguage"

Example: Redis HGETALL another example

127.0.0.1:6379> HSET user email [email protected]
(integer) 1
127.0.0.1:6379> HSET user lang English
(integer) 1
127.0.0.1:6379> HSET user gender Male
(integer) 1
127.0.0.1:6379> HGETALL user
1) "email"
2) "[email protected]"
3) "lang"
4) "English"
5) "gender"
6) "Male"

Previous: HGET
Next: HINCRBY



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/redis/redis-hgetall-key.php