{
  "schema_version": 2,
  "id": "commands/hgetall",
  "title": "HGETALL",
  "url": "https://redis.io/docs/latest/commands/hgetall/",
  "summary": "Returns all fields and values in a hash.",
  "since": "2.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-07-08T12:05:04+02:00",
  "page_type": "content",
  "content_hash": "9b5b374fc74b3910ca50044b548ced1064301e210e8b773507883c722c919af8",
  "sections": [
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key that holds the hash.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Foundational: Retrieve all fields and values from a hash using HGETALL (returns alternating field-value pairs, useful for loading entire hash data)\n\n**Difficulty:** Beginner\n\n**Commands:** HSET, HGETALL\n\n**Complexity:**\n- HSET: O(1)\n- HGETALL: O(N)\n\n**Available in:** Redis CLI, C, C#, Go, Java, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): a list of fields and their values, or an empty list when key does not exist.\n\n**RESP3:**\n\n[Map reply](../../develop/reference/protocol-spec#maps): a map of fields and their values, or an empty list when key does not exist."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "redis> HSET myhash field1 \"Hello\"\n(integer) 1\nredis> HSET myhash field2 \"World\"\n(integer) 1\nredis> HGETALL myhash\n1) \"field1\"\n2) \"Hello\"\n3) \"field2\"\n4) \"World\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "c",
      "code": "reply = redisCommand(c, \"HSET myhash field1 Hello field2 World\");\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"HGETALL myhash\");\n    for (size_t i = 0; i < reply->elements; i += 2) {\n        printf(\"%s=%s\\n\", reply->element[i]->str, reply->element[i + 1]->str);\n    }\n    // >>> field1=Hello\n    // >>> field2=World\n    freeReplyObject(reply);",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "csharp",
      "code": "db.HashSet(\"myhash\",\n            [\n                new(\"field1\", \"Hello\"),\n                new(\"field2\", \"World\")\n            ]\n        );\n\n        HashEntry[] hGetAllResult = db.HashGetAll(\"myhash\");\n        Array.Sort(hGetAllResult, (a1, a2) => a1.Name.CompareTo(a2.Name));\n        Console.WriteLine(\n            string.Join(\", \", hGetAllResult.Select(e => $\"{e.Name}: {e.Value}\"))\n        );\n        // >>> field1: Hello, field2: World",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "go",
      "code": "hGetAllResult1, err := rdb.HSet(ctx, \"myhash\",\n\t\t\"field1\", \"Hello\",\n\t\t\"field2\", \"World\",\n\t).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(hGetAllResult1) // >>> 2\n\n\thGetAllResult2, err := rdb.HGetAll(ctx, \"myhash\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tkeys := make([]string, 0, len(hGetAllResult2))\n\n\tfor key, _ := range hGetAllResult2 {\n\t\tkeys = append(keys, key)\n\t}\n\n\tsort.Strings(keys)\n\n\tfor _, key := range keys {\n\t\tfmt.Printf(\"Key: %v, value: %v\\n\", key, hGetAllResult2[key])\n\t}\n\t// >>> Key: field1, value: Hello\n\t// >>> Key: field2, value: World",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "Map<String, String> hGetAllFields = new HashMap<>();\n            hGetAllFields.put(\"field1\", \"Hello\");\n            hGetAllFields.put(\"field2\", \"World\");\n\n            syncCommands.hset(\"myhash\", hGetAllFields);\n\n            // `hgetall` returns a `Map`, whose iteration order isn't\n            // guaranteed. Wrap it in a `TreeMap` to sort the fields by name.\n            Map<String, String> res14 = syncCommands.hgetall(\"myhash\");\n            System.out.println(new TreeMap<>(res14));\n            // >>> {field1=Hello, field2=World}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "Map<String, String> hGetAllExampleParams = new HashMap<>();\n            hGetAllExampleParams.put(\"field1\", \"Hello\");\n            hGetAllExampleParams.put(\"field2\", \"World\");\n\n            CompletableFuture<Void> hGetAllExample = asyncCommands.hset(\"myhash\", hGetAllExampleParams).thenCompose(res1 -> {\n                return asyncCommands.hgetall(\"myhash\");\n            }).thenAccept(res2 -> {\n                System.out.println(res2);\n                // >>> {field1=Hello, field2=World}\n            }).toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "java",
      "code": "Map<String, String> hGetAllExampleParams = new HashMap<>();\n            hGetAllExampleParams.put(\"field1\", \"Hello\");\n            hGetAllExampleParams.put(\"field2\", \"World\");\n\n            Mono<Long> hGetAllExample1 = reactiveCommands.hset(\"myhash\", hGetAllExampleParams).doOnNext(result -> {\n            });\n\n            hGetAllExample1.block();\n\n            Mono<Map<String, String>> hGetAllExample2 = reactiveCommands.hgetall(\"myhash\").collectMap(\n                    KeyValue::getKey, KeyValue::getValue\n            ).doOnNext(result -> {\n                System.out.println(result);\n                // >>> {field1=Hello, field2=World}\n            });",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "java",
      "code": "Map<String, String> hGetAllExampleParams = new HashMap<>();\n        hGetAllExampleParams.put(\"field1\", \"Hello\");\n        hGetAllExampleParams.put(\"field2\", \"World\");\n\n        long hGetAllResult1 = jedis.hset(\"myhash\", hGetAllExampleParams);\n        System.out.println(hGetAllResult1); // >>> 2\n\n        Map<String, String> hGetAllResult2 = jedis.hgetAll(\"myhash\");\n        System.out.println(\n            hGetAllResult2.entrySet().stream()\n                    .sorted((s1, s2)-> s1.getKey().compareTo(s2.getKey()))\n                    .collect(toList())\n                    .toString()\n        );\n        // >>> [field1=Hello, field2=World]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "const res10 = await client.hSet(\n  'myhash',\n  {\n    'field1': 'Hello',\n    'field2': 'World'\n  }\n)\n\nconst res11 = await client.hGetAll('myhash')\nconsole.log(res11) // [Object: null prototype] { field1: 'Hello', field2: 'World' }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "await redis.hset('myhash', { field1: 'Hello', field2: 'World' });\n\nconst hgetallRes = await redis.hgetall('myhash');\nconsole.log(hgetallRes); // >>> { field1: 'Hello', field2: 'World' }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "javascript",
      "code": "const res10 = await client.hSet(\n  'myhash',\n  {\n    'field1': 'Hello',\n    'field2': 'World'\n  }\n)\n\nconst res11 = await client.hGetAll('myhash')\nconsole.log(res11) // [Object: null prototype] { field1: 'Hello', field2: 'World' }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "javascript",
      "code": "await redis.hset('myhash', { field1: 'Hello', field2: 'World' });\n\nconst hgetallRes = await redis.hgetall('myhash');\nconsole.log(hgetallRes); // >>> { field1: 'Hello', field2: 'World' }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "php",
      "code": "$hGetAllResult1 = $this->redis->hmset('myhash', ['field1' => 'Hello', 'field2' => 'World']);\n        echo \"HMSET myhash field1 Hello field2 World: \" . ($hGetAllResult1 ? 'OK' : 'FAIL') . \"\\n\"; // >>> OK\n\n        $hGetAllResult2 = $this->redis->hgetall('myhash');\n        echo \"HGETALL myhash: \" . json_encode($hGetAllResult2) . \"\\n\"; // >>> {\"field1\":\"Hello\",\"field2\":\"World\"}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "python",
      "code": "res10 = r.hset(\"myhash\", mapping={\"field1\": \"Hello\", \"field2\": \"World\"})\n\nres11 = r.hgetall(\"myhash\")\nprint(res11) # >>> { \"field1\": \"Hello\", \"field2\": \"World\" }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "ruby",
      "code": "r.hset('myhash', { 'field1' => 'Hello', 'field2' => 'World' })\n\nres14 = r.hgetall('myhash')\nputs res14.inspect # >>> {\"field1\"=>\"Hello\", \"field2\"=>\"World\"}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex15",
      "language": "rust",
      "code": "let hash_fields = [\n            (\"field1\", \"Hello\"),\n            (\"field2\", \"World\"),\n        ];\n\n        if let Ok(_) = r.hset_multiple::<&str, &str, &str, String>(\"myhash\", &hash_fields).await {\n            // Fields set successfully\n        }\n\n        match r.hgetall(\"myhash\").await {\n            Ok(res11) => {\n                let res11: HashMap<String, String> = res11;\n                println!(\"{res11:?}\");    // >>> {\"field1\": \"Hello\", \"field2\": \"World\"}\n            },\n            Err(e) => {\n                println!(\"Error getting all hash fields: {e}\");\n                return;\n            }\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex16",
      "language": "rust",
      "code": "let hash_fields = [\n            (\"field1\", \"Hello\"),\n            (\"field2\", \"World\"),\n        ];\n\n        if let Ok(_) = r.hset_multiple::<&str, &str, &str, String>(\"myhash\", &hash_fields) {\n            // Fields set successfully\n        }\n\n        match r.hgetall(\"myhash\") {\n            Ok(res11) => {\n                let res11: HashMap<String, String> = res11;\n                println!(\"{res11:?}\");    // >>> {\"field1\": \"Hello\", \"field2\": \"World\"}\n            },\n            Err(e) => {\n                println!(\"Error getting all hash fields: {e}\");\n                return;\n            }\n        }",
      "section_id": "examples"
    }
  ]
}
