VOOZH about

URL: https://redis.io/docs/latest/commands/hgetall/

⇱ HGETALL | Docs


{"acl_categories":["@read","@hash","@slow"],"arguments":[{"display_text":"key","key_spec_index":0,"name":"key","type":"key"}],"arity":2,"categories":["docs","develop","stack","oss","rs","rc","oss","kubernetes","clients"],"command_flags":["readonly"],"complexity":"O(N) where N is the size of the hash.","description":"Returns all fields and values in a hash.","duplicateOf":"head:data-ai-metadata","group":"hash","key_specs":[{"RO":true,"access":true,"begin_search":{"spec":{"index":1},"type":"index"},"find_keys":{"spec":{"keystep":1,"lastkey":0,"limit":0},"type":"range"}}],"location":"body","since":"2.0.0","syntax_fmt":"HGETALL key","title":"HGETALL","tableOfContents":{"sections":[{"id":"required-arguments","title":"Required arguments"},{"id":"examples","title":"Examples"},{"id":"redis-software-and-redis-cloud-compatibility","title":"Redis Software and Redis Cloud compatibility"},{"id":"return-information","title":"Return information"}]},"codeExamples":[{"codetabsId":"cmds_hash-stephgetall","commands":[{"acl_categories":["@write","@hash","@fast"],"complexity":"O(1)","name":"HSET"},{"acl_categories":["@read","@hash","@slow"],"complexity":"O(N)","name":"HGETALL"}],"description":"Foundational: Retrieve all fields and values from a hash using HGETALL (returns alternating field-value pairs, useful for loading entire hash data)","difficulty":"beginner","id":"hgetall","languages":[{"id":"redis-cli","panelId":"panel_redis-cli_cmds_hash-stephgetall"},{"clientId":"redis-py","clientName":"redis-py","id":"Python","langId":"python","panelId":"panel_Python_cmds_hash-stephgetall"},{"id":"Node-js","panelId":"panel_Nodejs_cmds_hash-stephgetall"},{"clientId":"ioredis","clientName":"ioredis","id":"ioredis","langId":"javascript","panelId":"panel_ioredis_cmds_hash-stephgetall"},{"clientId":"jedis","clientName":"Jedis","id":"Java-Sync","langId":"java","panelId":"panel_Java-Sync_cmds_hash-stephgetall"},{"clientId":"lettuce","clientName":"Lettuce","id":"Java-Async","langId":"java","panelId":"panel_Java-Async_cmds_hash-stephgetall"},{"clientId":"lettuce","clientName":"Lettuce","id":"Java-Reactive","langId":"java","panelId":"panel_Java-Reactive_cmds_hash-stephgetall"},{"clientId":"go-redis","clientName":"go-redis","id":"Go","langId":"go","panelId":"panel_Go_cmds_hash-stephgetall"},{"clientId":"hiredis","clientName":"hiredis","id":"C","langId":"c","panelId":"panel_C_cmds_hash-stephgetall"},{"id":"dotnet-Sync (SE-Redis)","panelId":"panel_Csharp-Sync (SERedis)_cmds_hash-stephgetall"},{"clientId":"predis","clientName":"Predis","id":"PHP","langId":"php","panelId":"panel_PHP_cmds_hash-stephgetall"},{"clientId":"redis-rs","clientName":"redis-rs","id":"Rust-Sync","langId":"rust","panelId":"panel_Rust-Sync_cmds_hash-stephgetall"},{"clientId":"redis-rs","clientName":"redis-rs","id":"Rust-Async","langId":"rust","panelId":"panel_Rust-Async_cmds_hash-stephgetall"}]}]}

HGETALL

HGETALL key
hgetall(
 name: str
) → Union[Awaitable[dict], dict]
HGETALL(
 key: RedisArgument
) → Any
hgetAll(
 key: String
) → Map<String, String> // All the fields and values contained into a hash.
hgetall(
 key: K // the key.
) → Map<K, V> // Long count of the keys.

hgetall(
 channel: KeyValueStreamingChannel<K, V>, // the channel.
 key: K // the key.
) → Long // Long count of the keys.
hgetall(
 key: K // the key.
) → RedisFuture<Map<K, V>> // Long count of the keys.

hgetall(
 channel: KeyValueStreamingChannel<K, V>, // the channel.
 key: K // the key.
) → RedisFuture<Long> // Long count of the keys.
hgetall(
 key: K // the key.
) → Flux<KeyValue<K, V>> // Long count of the keys. @deprecated since 6.0 in favor of consuming large results through the org.reactivestreams.Publisher returned by #hgetall.

hgetall(
 channel: KeyValueStreamingChannel<K, V>, // the channel.
 key: K // the key.
) → Mono<Long> // Long count of the keys. @deprecated since 6.0 in favor of consuming large results through the org.reactivestreams.Publisher returned by #hgetall.
HGetAll(
 ctx: context.Context,
 key: string
) → *MapStringStringCmd
HashGetAll(
 key: RedisKey, // The key of the hash to get all entries from.
 flags: CommandFlags // The flags to use for this operation.
) → HashEntry[] // List of fields and their values stored in the hash, or an empty list when key does not exist.

HashGetAll(
 key: RedisKey, // The key of the hash to get all entries from.
 flags: CommandFlags // The flags to use for this operation.
) → HashEntry[] // List of fields and their values stored in the hash, or an empty list when key does not exist.
HashGetAll(
 key: RedisKey, // The key of the hash to get all entries from.
 flags: CommandFlags // The flags to use for this operation.
) → HashEntry[] // List of fields and their values stored in the hash, or an empty list when key does not exist.

HashGetAll(
 key: RedisKey, // The key of the hash to get all entries from.
 flags: CommandFlags // The flags to use for this operation.
) → HashEntry[] // List of fields and their values stored in the hash, or an empty list when key does not exist.
hgetall(
 $key: string
) → array
hgetall(
 key: K
) → (std::collections::HashMap<String, String>)
hgetall(
 key: K
) → (std::collections::HashMap<String, String>)
Available since:
Redis Open Source 2.0.0
Time complexity:
O(N) where N is the size of the hash.
ACL categories:
@read, @hash, @slow,
Compatibility:
Redis Software and Redis Cloud compatibility

Returns 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.

Required arguments

Examples

Foundational: Retrieve all fields and values from a hash using HGETALL (returns alternating field-value pairs, useful for loading entire hash data)
redis> HSET myhash field1 "Hello"
(integer) 1
redis> HSET myhash field2 "World"
(integer) 1
redis> HGETALL myhash
1) "field1"
2) "Hello"
3) "field2"
4) "World"
Redis CLI guide
Also, check out our other client tools Redis Insight and Redis for VS Code.
res10 = r.hset("myhash", mapping={"field1": "Hello", "field2": "World"})
res11 = r.hgetall("myhash")
print(res11) # >>> { "field1": "Hello", "field2": "World" }
  • Creates or modifies the value of a field in a hash.
    • hset(
      • name: str,
      • key: Optional[str] = None,
      • value: Optional[str] = None,
      • mapping: Optional[dict] = None,
      • items: Optional[list] = None
      ) Union[Awaitable[int], int]
  • Returns all fields and values in a hash.
    • hgetall(
      • name: str
      ) Union[Awaitable[dict], dict]
const res10 = await client.hSet(
 'myhash',
 {
 'field1': 'Hello',
 'field2': 'World'
 }
)
const res11 = await client.hGetAll('myhash')
console.log(res11) // [Object: null prototype] { field1: 'Hello', field2: 'World' }
  • Creates or modifies the value of a field in a hash.
    • HSET(
      • ...[key, value, fieldValue]: SingleFieldArguments | MultipleFieldsArguments
      ) Any
  • Returns all fields and values in a hash.
    • HGETALL(
      • key: RedisArgument
      ) Any
import assert from 'node:assert';
import { Redis } from 'ioredis';
const redis = new Redis();
await redis.hset('myhash', { field1: 'Hello', field2: 'World' });
const hmgetResult = await redis.hmget('myhash', 'field1', 'field2', 'nofield');
console.log(hmgetResult); // >>> ['Hello', 'World', null]
redis.disconnect();
  • Creates or modifies the value of a field in a hash.
    • hset(
      • key: RedisKey,
      • object: object,
      • callback?: Callback<number>
      ) Any
    • hset(
      • key: RedisKey,
      • map: Map<string | Buffer | number, string | Buffer | number>,
      • callback?: Callback<number>
      ) Any
    • hset(
      • ...args: [, key
      ) Any
    • hset(
      • ...args: [key
      ) Any
  • Returns all fields and values in a hash.
    • hgetall(
      • key: RedisKey,
      • callback?: Callback<Record<string, string>>
      ) Any
Map<String,String>hGetAllExampleParams=newHashMap<>();hGetAllExampleParams.put("field1","Hello");hGetAllExampleParams.put("field2","World");longhGetAllResult1=jedis.hset("myhash",hGetAllExampleParams);System.out.println(hGetAllResult1);// >>> 2Map<String,String>hGetAllResult2=jedis.hgetAll("myhash");System.out.println(hGetAllResult2.entrySet().stream().sorted((s1,s2)->s1.getKey().compareTo(s2.getKey())).collect(toList()).toString());// >>> [field1=Hello, field2=World]
  • Creates or modifies the value of a field in a hash.
    • hset(
      • key: byte[],
      • field: byte[],
      • value: byte[]
      ) long // If the field already exists, and the HSET just produced an update of the value, 0 is returned, otherwise if a new field is created 1 is returned.
    • hset(
      • key: byte[],
      • hash: Map<byte[], byte[]>
      ) long // If the field already exists, and the HSET just produced an update of the value, 0 is returned, otherwise if a new field is created 1 is returned.
    • hset(
      • key: String,
      • field: String,
      • value: String
      ) long // If the field already exists, and the HSET just produced an update of the value, 0 is returned, otherwise if a new field is created 1 is returned.
    • hset(
      • key: String,
      • hash: Map<String, String>
      ) long // If the field already exists, and the HSET just produced an update of the value, 0 is returned, otherwise if a new field is created 1 is returned.
  • Returns all fields and values in a hash.
    • hgetAll(
      • key: String
      ) Map<String, String> // All the fields and values contained into a hash.
Map<String,String>hGetAllExampleParams=newHashMap<>();hGetAllExampleParams.put("field1","Hello");hGetAllExampleParams.put("field2","World");CompletableFuture<Void>hGetAllExample=asyncCommands.hset("myhash",hGetAllExampleParams).thenCompose(res1->{returnasyncCommands.hgetall("myhash");}).thenAccept(res2->{System.out.println(res2);// >>> {field1=Hello, field2=World}}).toCompletableFuture();
  • Creates or modifies the value of a field in a hash.
    • hset(
      • key: K, // the key of the hash.
      • field: K,
      • value: V
      ) RedisFuture<Boolean> // Long integer-reply: the number of fields that were added. @since 5.3
    • hset(
      • key: K, // the key of the hash.
      • map: Map<K, V> // the field/value pairs to update.
      ) RedisFuture<Long> // Long integer-reply: the number of fields that were added. @since 5.3
  • Returns all fields and values in a hash.
    • hgetall(
      • key: K // the key.
      ) RedisFuture<Map<K, V>> // Long count of the keys.
    • hgetall(
      • channel: KeyValueStreamingChannel<K, V>, // the channel.
      • key: K // the key.
      ) RedisFuture<Long> // Long count of the keys.
Map<String,String>hGetAllExampleParams=newHashMap<>();hGetAllExampleParams.put("field1","Hello");hGetAllExampleParams.put("field2","World");Mono<Long>hGetAllExample1=reactiveCommands.hset("myhash",hGetAllExampleParams).doOnNext(result->{});hGetAllExample1.block();Mono<Map<String,String>>hGetAllExample2=reactiveCommands.hgetall("myhash").collectMap(KeyValue::getKey,KeyValue::getValue).doOnNext(result->{System.out.println(result);// >>> {field1=Hello, field2=World}});
  • Creates or modifies the value of a field in a hash.
    • hset(
      • key: K, // the key of the hash.
      • field: K,
      • value: V
      ) Mono<Boolean> // Long integer-reply: the number of fields that were added. @since 5.3
    • hset(
      • key: K, // the key of the hash.
      • map: Map<K, V> // the field/value pairs to update.
      ) Mono<Long> // Long integer-reply: the number of fields that were added. @since 5.3
  • Returns all fields and values in a hash.
    • hgetall(
      • key: K // the key.
      ) Flux<KeyValue<K, V>> // Long count of the keys. @deprecated since 6.0 in favor of consuming large results through the org.reactivestreams.Publisher returned by #hgetall.
    • hgetall(
      • channel: KeyValueStreamingChannel<K, V>, // the channel.
      • key: K // the key.
      ) Mono<Long> // Long count of the keys. @deprecated since 6.0 in favor of consuming large results through the org.reactivestreams.Publisher returned by #hgetall.
	hGetAllResult1, err := rdb.HSet(ctx, "myhash",
		"field1", "Hello",
		"field2", "World",
	).Result()
	if err != nil {
		panic(err)
	}
	fmt.Println(hGetAllResult1) // >>> 2
	hGetAllResult2, err := rdb.HGetAll(ctx, "myhash").Result()
	if err != nil {
		panic(err)
	}
	keys := make([]string, 0, len(hGetAllResult2))
	for key, _ := range hGetAllResult2 {
		keys = append(keys, key)
	}
	sort.Strings(keys)
	for _, key := range keys {
		fmt.Printf("Key: %v, value: %v\n", key, hGetAllResult2[key])
	}
	// >>> Key: field1, value: Hello
	// >>> Key: field2, value: World
  • Creates or modifies the value of a field in a hash.
    • HSet(
      • ctx: context.Context,
      • key: string,
      • values: ...interface{}
      ) *IntCmd
  • Returns all fields and values in a hash.
    • HGetAll(
      • ctx: context.Context,
      • key: string
      ) *MapStringStringCmd
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <hiredis/hiredis.h>int main(int argc, char **argv) {
 redisContext *c = redisConnect("127.0.0.1", 6379);
 if (c == NULL || c->err) {
 if (c) {
 printf("Connection error: %s\n", c->errstr);
 redisFree(c);
 } else {
 printf("Connection error: can't allocate redis context\n");
 }
 return 1;
 }
 redisReply *reply;
 // Set up hash with fields
 reply = redisCommand(c, "HSET %s %s %s %s %s",
 "myhash", "field1", "Hello", "field2", "World");
 freeReplyObject(reply);
 // Get multiple fields at once
 reply = redisCommand(c, "HMGET %s %s %s %s",
 "myhash", "field1", "field2", "nofield");
 printf("HMGET myhash field1 field2 nofield:\n");
 for (size_t i = 0; i < reply->elements; i++) {
 if (reply->element[i]->type == REDIS_REPLY_NIL) {
 printf(" [%zu]: null\n", i);
 } else {
 printf(" [%zu]: %s\n", i, reply->element[i]->str);
 }
 }
 // >>> [0]: Hello
 // >>> [1]: World
 // >>> [2]: null
 freeReplyObject(reply);
 redisFree(c);
 return 0;
}
 db.HashSet("myhash",
 [
 new("field1", "Hello"),
 new("field2", "World")
 ]
 );
 HashEntry[] hGetAllResult = db.HashGetAll("myhash");
 Array.Sort(hGetAllResult, (a1, a2) => a1.Name.CompareTo(a2.Name));
 Console.WriteLine(
 string.Join(", ", hGetAllResult.Select(e => $"{e.Name}: {e.Value}"))
 );
 // >>> field1: Hello, field2: World
  • Creates or modifies the value of a field in a hash.
    • HashSet(
      • key: RedisKey, // The key of the hash.
      • hashFields: HashEntry[],
      • flags: CommandFlags // The flags to use for this operation.
      ) void // true if field is a new field in the hash and value was set, false if field already exists in the hash and the value was updated.
    • HashSet(
      • key: RedisKey, // The key of the hash.
      • hashField: RedisValue, // The field to set in the hash.
      • value: RedisValue, // The value to set.
      • when: When, // Which conditions under which to set the field value (defaults to always).
      • flags: CommandFlags // The flags to use for this operation.
      ) bool // true if field is a new field in the hash and value was set, false if field already exists in the hash and the value was updated.
    • HashSet(
      • key: RedisKey, // The key of the hash.
      • hashField: RedisValue, // The field to set in the hash.
      • value: RedisValue, // The value to set.
      • when: When, // Which conditions under which to set the field value (defaults to always).
      • flags: CommandFlags // The flags to use for this operation.
      ) bool // true if field is a new field in the hash and value was set, false if field already exists in the hash and the value was updated.
    • HashSet(
      • key: RedisKey, // The key of the hash.
      • hashFields: HashEntry[],
      • flags: CommandFlags // The flags to use for this operation.
      ) void // true if field is a new field in the hash and value was set, false if field already exists in the hash and the value was updated.
  • Returns all fields and values in a hash.
    • HashGetAll(
      • key: RedisKey, // The key of the hash to get all entries from.
      • flags: CommandFlags // The flags to use for this operation.
      ) HashEntry[] // List of fields and their values stored in the hash, or an empty list when key does not exist.
    • HashGetAll(
      • key: RedisKey, // The key of the hash to get all entries from.
      • flags: CommandFlags // The flags to use for this operation.
      ) HashEntry[] // List of fields and their values stored in the hash, or an empty list when key does not exist.
 $hGetAllResult1 = $this->redis->hmset('myhash', ['field1' => 'Hello', 'field2' => 'World']);
 echo "HMSET myhash field1 Hello field2 World: " . ($hGetAllResult1 ? 'OK' : 'FAIL') . "\n"; // >>> OK
 $hGetAllResult2 = $this->redis->hgetall('myhash');
 echo "HGETALL myhash: " . json_encode($hGetAllResult2) . "\n"; // >>> {"field1":"Hello","field2":"World"}
lethash_fields=[("field1","Hello"),("field2","World"),];ifletOk(_)=r.hset_multiple::<&str,&str,&str,String>("myhash",&hash_fields){// Fields set successfully
}matchr.hgetall("myhash"){Ok(res11)=>{letres11: HashMap<String,String>=res11;println!("{res11:?}");// >>> {"field1": "Hello", "field2": "World"}
},Err(e)=>{println!("Error getting all hash fields: {e}");return;}}
lethash_fields=[("field1","Hello"),("field2","World"),];ifletOk(_)=r.hset_multiple::<&str,&str,&str,String>("myhash",&hash_fields).await{// Fields set successfully
}matchr.hgetall("myhash").await{Ok(res11)=>{letres11: HashMap<String,String>=res11;println!("{res11:?}");// >>> {"field1": "Hello", "field2": "World"}
},Err(e)=>{println!("Error getting all hash fields: {e}");return;}}

Give these commands a try in the interactive console:

Redis Software and Redis Cloud compatibility

Redis
Software
Redis
Cloud
Notes
✅ Standard
✅ Standard

Return information

Array reply: a list of fields and their values, or an empty list when key does not exist.
Map reply: a map of fields and their values, or an empty list when key does not exist.