{
  "schema_version": 2,
  "id": "commands/mget",
  "title": "MGET",
  "url": "https://redis.io/docs/latest/commands/mget/",
  "summary": "Atomically returns the string values of one or more keys.",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T16:45:12+01:00",
  "page_type": "content",
  "content_hash": "e075beee7156c00afef43e08616b2e4781f15bad4844e45ef483a267390f21fa",
  "sections": [
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key [key ...]</code></summary>\n\nOne or more keys whose values to retrieve.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Returns the values of all specified keys.\n\n**Difficulty:** Beginner\n\n**Commands:** SET, MGET\n\n**Complexity:**\n- SET: O(1)\n- MGET: O(N)\n\n**Available in:** Redis CLI, C, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, 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 (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##### 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 at the specified keys.\n\n**RESP3:**\n\n[Array reply](../../develop/reference/protocol-spec#arrays): a list of values at the specified keys."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> SET key1 \"Hello\"\nOK\n> SET key2 \"World\"\nOK\n> MGET key1 key2 nonexisting\n1) \"Hello\"\n2) \"World\"\n3) (nil)",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "c",
      "code": "redisReply *reply = redisCommand(c, \"SET key1 Hello\");\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"SET key2 World\");\n    freeReplyObject(reply);\n\n    reply = redisCommand(c, \"MGET key1 key2 nonexisting\");\n\n    for (size_t i = 0; i < reply->elements; i++) {\n        if (i > 0) {\n            printf(\", \");\n        }\n\n        if (reply->element[i]->type == REDIS_REPLY_NIL) {\n            printf(\"null\");\n        } else {\n            printf(\"%s\", reply->element[i]->str);\n        }\n    }\n    printf(\"\\n\");\n    // >>> Hello, World, null",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "csharp",
      "code": "bool mgetResult1 = db.StringSet(\"key1\", \"Hello\");\n        bool mgetResult2 = db.StringSet(\"key2\", \"World\");\n\n        RedisValue[] mgetResult3 = db.StringGet(new RedisKey[] { \"key1\", \"key2\", \"nonexisting\" });\n        Console.WriteLine(string.Join(\", \", mgetResult3.Select(v => v.IsNull ? \"null\" : v.ToString())));\n        // >>> Hello, World, null",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "go",
      "code": "if err := rdb.Set(ctx, \"key1\", \"Hello\", 0).Err(); err != nil {\n\t\tpanic(err)\n\t}\n\n\tif err := rdb.Set(ctx, \"key2\", \"World\", 0).Err(); err != nil {\n\t\tpanic(err)\n\t}\n\n\tmgetResult, err := rdb.MGet(ctx, \"key1\", \"key2\", \"nonexisting\").Result()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(mgetResult) // >>> [Hello World <nil>]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "CompletableFuture<Void> mgetExample = asyncCommands.set(\"key1\", \"Hello\")\n                    .thenCompose(res1 -> asyncCommands.set(\"key2\", \"World\"))\n                    .thenCompose(res2 -> asyncCommands.mget(\"key1\", \"key2\", \"nonexisting\"))\n                    .thenAccept(res3 -> {\n                        System.out.println(res3);\n                        // >>> [KeyValue[key1, Hello], KeyValue[key2, World], KeyValue[nonexisting].empty]\n                    })\n                    .toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "Mono<Void> mgetExample = reactiveCommands.set(\"key1\", \"Hello\")\n                    .flatMap(res1 -> reactiveCommands.set(\"key2\", \"World\"))\n                    .flatMap(res2 -> reactiveCommands.mget(\"key1\", \"key2\", \"nonexisting\").collectList())\n                    .doOnNext(res3 -> {\n                        System.out.println(res3);\n                        // >>> [KeyValue[key1, Hello], KeyValue[key2, World], KeyValue[nonexisting].empty]\n                    })\n                    .then();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "java",
      "code": "String mgetResult1 = jedis.set(\"key1\", \"Hello\");\n        System.out.println(mgetResult1);    // >>> OK\n\n        String mgetResult2 = jedis.set(\"key2\", \"World\");\n        System.out.println(mgetResult2);    // >>> OK\n\n        java.util.List<String> mgetResult3 = jedis.mget(\"key1\", \"key2\", \"nonexisting\");\n        System.out.println(mgetResult3);    // >>> [Hello, World, null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "javascript",
      "code": "await client.set('key1', 'Hello');\nawait client.set('key2', 'World');\n\nconst mgetResult = await client.mGet(['key1', 'key2', 'nonexisting']);\nconsole.log(mgetResult); // >>> [ 'Hello', 'World', null ]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "await redis.set('key1', 'Hello');\nawait redis.set('key2', 'World');\n\nconst mgetResult = await redis.mget('key1', 'key2', 'nonexisting');\nconsole.log(mgetResult); // >>> ['Hello', 'World', null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "await client.set('key1', 'Hello');\nawait client.set('key2', 'World');\n\nconst mgetResult = await client.mGet(['key1', 'key2', 'nonexisting']);\nconsole.log(mgetResult); // >>> [ 'Hello', 'World', null ]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "javascript",
      "code": "await redis.set('key1', 'Hello');\nawait redis.set('key2', 'World');\n\nconst mgetResult = await redis.mget('key1', 'key2', 'nonexisting');\nconsole.log(mgetResult); // >>> ['Hello', 'World', null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "php",
      "code": "$r->set('key1', 'Hello');\n        $r->set('key2', 'World');\n\n        $mgetResult = $r->mget(['key1', 'key2', 'nonexisting']);\n        echo json_encode($mgetResult) . PHP_EOL; // >>> [\"Hello\",\"World\",null]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "python",
      "code": "r.set(\"key1\", \"Hello\")\nr.set(\"key2\", \"World\")\n\nmget_result = r.mget(\"key1\", \"key2\", \"nonexisting\")\nprint(mget_result)\n# >>> ['Hello', 'World', None]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "rust",
      "code": "if let Ok(res) = r.set(\"key1\", \"Hello\").await {\n            let _: String = res;\n        }\n\n        if let Ok(res) = r.set(\"key2\", \"World\").await {\n            let _: String = res;\n        }\n\n        match r.mget(&[\"key1\", \"key2\", \"nonexisting\"]).await {\n            Ok(mget_result) => {\n                let mget_result: Vec<Option<String>> = mget_result;\n                println!(\"{mget_result:?}\");    // >>> [Some(\"Hello\"), Some(\"World\"), None]\n            }\n            Err(e) => {\n                println!(\"Error getting values: {e}\");\n            }\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "rust",
      "code": "if let Ok(res) = r.set(\"key1\", \"Hello\") {\n            let _: String = res;\n        }\n\n        if let Ok(res) = r.set(\"key2\", \"World\") {\n            let _: String = res;\n        }\n\n        match r.mget(&[\"key1\", \"key2\", \"nonexisting\"]) {\n            Ok(mget_result) => {\n                let mget_result: Vec<Option<String>> = mget_result;\n                println!(\"{mget_result:?}\");    // >>> [Some(\"Hello\"), Some(\"World\"), None]\n            }\n            Err(e) => {\n                println!(\"Error getting values: {e}\");\n            }\n        }",
      "section_id": "examples"
    }
  ]
}
