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" }
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' }
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>
-
hset(
- key: RedisKey,
- map: Map<string | Buffer | number, string | Buffer | number>,
- callback?: Callback<number>
-
hset(
- ...args: [, key
-
hset(
- ...args: [key
-
hset(
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[]
-
hset(
- key: byte[],
- hash: Map<byte[], byte[]>
-
hset(
- key: String,
- field: String,
- value: String
-
hset(
- key: String,
- hash: Map<String, String>
-
hset(
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
-
hset(
- key: K, // the key of the hash.
- map: Map<K, V> // the field/value pairs to update.
-
hset(
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
-
hset(
- key: K, // the key of the hash.
- map: Map<K, V> // the field/value pairs to update.
-
hset(
-
Returns all fields and values in a hash.
-
hgetall(
- key: K // the key.
-
hgetall(
- channel: KeyValueStreamingChannel<K, V>, // the channel.
- key: K // the key.
-
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
#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.
-
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.
-
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.
-
HashSet(
- key: RedisKey, // The key of the hash.
- hashFields: HashEntry[],
- flags: CommandFlags // The flags to use for this operation.
-
HashSet(
-
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.
-
HashGetAll(
- key: RedisKey, // The key of the hash to get all entries from.
- flags: CommandFlags // The flags to use for this operation.
-
HashGetAll(
$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.
