{
  "schema_version": 2,
  "id": "commands/hmget",
  "title": "HMGET",
  "url": "https://redis.io/docs/latest/commands/hmget/",
  "summary": "Returns the values of all fields in a hash.",
  "since": "2.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-07-20T16:12:55+02:00",
  "page_type": "content",
  "content_hash": "f04b9a8f1caf71dd9c16fa32ab94b43d6912bce2ee2e9b62dc84ad724ebf1ae0",
  "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>\n\n<details open><summary><code>field [field ...]</code></summary>\n\nOne or more fields whose values to retrieve.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Foundational: Retrieve multiple field values from a hash using HMGET (returns nil if field or key doesn't exist)\n\n**Difficulty:** Beginner\n\n**Commands:** HSET, HMGET\n\n**Complexity:**\n- HSET: O(1)\n- HMGET: 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 values associated with the given fields, in the same order as they are requested.\n\n**RESP3:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): a list of values associated with the given fields, in the same order as they are requested."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> HSET myhash field1 \"Hello\"\n(integer) 1\n> HSET myhash field2 \"World\"\n(integer) 1\n> HMGET myhash field1 field2 nofield\n1) \"Hello\"\n2) \"World\"\n3) (nil)",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "c",
      "code": "redisReply *reply;\n\n    // Set up hash with fields\n    reply = redisCommand(c, \"HSET %s %s %s %s %s\",\n        \"myhash\", \"field1\", \"Hello\", \"field2\", \"World\");\n    freeReplyObject(reply);\n\n    // Get multiple fields at once\n    reply = redisCommand(c, \"HMGET %s %s %s %s\",\n        \"myhash\", \"field1\", \"field2\", \"nofield\");\n\n    printf(\"HMGET myhash field1 field2 nofield:\\n\");\n    for (size_t i = 0; i < reply->elements; i++) {\n        if (reply->element[i]->type == REDIS_REPLY_NIL) {\n            printf(\"  [%zu]: null\\n\", i);\n        } else {\n            printf(\"  [%zu]: %s\\n\", i, reply->element[i]->str);\n        }\n    }\n    // >>> [0]: Hello\n    // >>> [1]: World\n    // >>> [2]: null",
      "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        RedisValue[] hmgetResult = db.HashGet(\"myhash\", new RedisValue[] { \"field1\", \"field2\", \"nofield\" });\n        Console.WriteLine(string.Join(\", \", hmgetResult.Select(v => v.IsNull ? \"null\" : v.ToString())));\n        // >>> Hello, World, null",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "go",
      "code": "rdb.HSet(ctx, \"myhash\", \"field1\", \"Hello\", \"field2\", \"World\")\n\n\thmgetResult, err := rdb.HMGet(ctx, \"myhash\", \"field1\", \"field2\", \"nofield\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(hmgetResult) // >>> [Hello World <nil>]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "Map<String, String> hmgetFields = new HashMap<>();\n            hmgetFields.put(\"field1\", \"Hello\");\n            hmgetFields.put(\"field2\", \"World\");\n\n            syncCommands.hset(\"myhash\", hmgetFields);\n\n            // `hmget` returns a `KeyValue` for each field you ask for, in the\n            // order you asked for them. A field that doesn't exist comes back\n            // as an empty `KeyValue`.\n            List<KeyValue<String, String>> res13 = syncCommands.hmget(\"myhash\", \"field1\", \"field2\", \"nofield\");\n            System.out.println(res13);\n            // >>> [KeyValue[field1, Hello], KeyValue[field2, World], KeyValue[nofield].empty]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "Map<String, String> hmgetExampleParams = new HashMap<>();\n            hmgetExampleParams.put(\"field1\", \"Hello\");\n            hmgetExampleParams.put(\"field2\", \"World\");\n\n            CompletableFuture<Void> hmgetExample = asyncCommands.hset(\"myhash\", hmgetExampleParams).thenCompose(res1 -> {\n                return asyncCommands.hmget(\"myhash\", \"field1\", \"field2\", \"nofield\");\n            }).thenAccept(res2 -> {\n                System.out.println(res2); // >>> [KeyValue[field1, Hello], KeyValue[field2, World], KeyValue[nofield].empty]\n            }).toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "java",
      "code": "Map<String, String> hmgetExampleParams = new HashMap<>();\n            hmgetExampleParams.put(\"field1\", \"Hello\");\n            hmgetExampleParams.put(\"field2\", \"World\");\n\n            Mono<Long> hmgetExample1 = reactiveCommands.hset(\"myhash\", hmgetExampleParams);\n\n            hmgetExample1.block();\n\n            Flux<KeyValue<String, String>> hmgetExample2 = reactiveCommands.hmget(\"myhash\", \"field1\", \"field2\", \"nofield\")\n                    .doOnNext(result -> {\n                        System.out.println(result);\n                        // >>> KeyValue[field1, Hello]\n                        // >>> KeyValue[field2, World]\n                        // >>> KeyValue[nofield].empty\n                    });",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "java",
      "code": "Map<String, String> hmgetExampleParams = new HashMap<>();\n        hmgetExampleParams.put(\"field1\", \"Hello\");\n        hmgetExampleParams.put(\"field2\", \"World\");\n\n        jedis.hset(\"myhash\", hmgetExampleParams);\n\n        List<String> hmgetResult = jedis.hmget(\"myhash\", \"field1\", \"field2\", \"nofield\");\n        System.out.println(hmgetResult);    // >>> [Hello, World, null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "await client.hSet('myhash', { field1: 'Hello', field2: 'World' });\n\nconst hmgetResult = await client.hmGet('myhash', ['field1', 'field2', 'nofield']);\nconsole.log(hmgetResult); // ['Hello', 'World', null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "await redis.hset('myhash', { field1: 'Hello', field2: 'World' });\n\nconst hmgetResult = await redis.hmget('myhash', 'field1', 'field2', 'nofield');\nconsole.log(hmgetResult); // >>> ['Hello', 'World', null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "javascript",
      "code": "await client.hSet('myhash', { field1: 'Hello', field2: 'World' });\n\nconst hmgetResult = await client.hmGet('myhash', ['field1', 'field2', 'nofield']);\nconsole.log(hmgetResult); // ['Hello', 'World', null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "javascript",
      "code": "await redis.hset('myhash', { field1: 'Hello', field2: 'World' });\n\nconst hmgetResult = await redis.hmget('myhash', 'field1', 'field2', 'nofield');\nconsole.log(hmgetResult); // >>> ['Hello', 'World', null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "php",
      "code": "$this->redis->hmset('myhash', ['field1' => 'Hello', 'field2' => 'World']);\n\n        $hmgetResult = $this->redis->hmget('myhash', ['field1', 'field2', 'nofield']);\n        echo \"HMGET myhash field1 field2 nofield: \";\n        print_r($hmgetResult);\n        // >>> Array ( [0] => Hello [1] => World [2] => )",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "python",
      "code": "r.hset(\"myhash\", mapping={\"field1\": \"Hello\", \"field2\": \"World\"})\n\nhmget_result = r.hmget(\"myhash\", [\"field1\", \"field2\", \"nofield\"])\nprint(hmget_result)  # >>> ['Hello', 'World', None]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "ruby",
      "code": "r.hset('myhash', { 'field1' => 'Hello', 'field2' => 'World' })\n\nres13 = r.hmget('myhash', 'field1', 'field2', 'nofield')\nputs res13.inspect # >>> [\"Hello\", \"World\", nil]",
      "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.hmget::<&str, &[&str], Vec<Option<String>>>(\"myhash\", &[\"field1\", \"field2\", \"nofield\"]).await {\n            Ok(hmget_result) => {\n                println!(\"{:?}\", hmget_result);    // >>> [Some(\"Hello\"), Some(\"World\"), None]\n            },\n            Err(e) => {\n                println!(\"Error getting 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.hmget::<&str, &[&str], Vec<Option<String>>>(\"myhash\", &[\"field1\", \"field2\", \"nofield\"]) {\n            Ok(hmget_result) => {\n                println!(\"{:?}\", hmget_result);    // >>> [Some(\"Hello\"), Some(\"World\"), None]\n            },\n            Err(e) => {\n                println!(\"Error getting hash fields: {e}\");\n                return;\n            }\n        }",
      "section_id": "examples"
    }
  ]
}
