{
  "schema_version": 2,
  "id": "commands/get",
  "title": "GET",
  "url": "https://redis.io/docs/latest/commands/get/",
  "summary": "Returns the string value of a key.",
  "since": "1.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": "eb1f30d1ffbb745bd6f07f247c27b266fdfccb65ef56e297aa68a2983a9bc89f",
  "sections": [
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Foundational: Retrieve the string value of a key using GET (returns nil if key doesn't exist)\n\n**Difficulty:** Beginner\n\n**Commands:** GET, SET\n\n**Complexity:**\n- GET: O(1)\n- SET: O(1)\n\n**Available in:** Redis CLI, C#, Go, 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##### 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##### 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\nOne of the following:\n* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the value of the key.\n* [Nil reply](../../develop/reference/protocol-spec#bulk-strings): if the key does not exist.\n\n**RESP3:**\n\nOne of the following:\n* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the value of the key.\n* [Null reply](../../develop/reference/protocol-spec#nulls): key does not exist."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "> GET nonexisting\n(nil)\n> SET mykey \"Hello\"\nOK\n> GET mykey\n\"Hello\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "csharp",
      "code": "using NRedisStack.Tests;\nusing StackExchange.Redis;\n\npublic class SetGetExample\n{\n    public void Run()\n    {\n        var muxer = ConnectionMultiplexer.Connect(\"localhost:6379\");\n        var db = muxer.GetDatabase();\n\n        bool status = db.StringSet(\"bike:1\", \"Process 134\");\n\n        if (status)\n            Console.WriteLine(\"Successfully added a bike.\");\n\n        var value = db.StringGet(\"bike:1\");\n\n        if (value.HasValue)\n            Console.WriteLine(\"The name of the bike is: \" + value + \".\");\n\n    }\n}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "go",
      "code": "package example_commands_test\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/redis/go-redis/v9\"\n)\n\nfunc ExampleClient_Set_and_get() {\n\tctx := context.Background()\n\n\trdb := redis.NewClient(&redis.Options{\n\t\tAddr:     \"localhost:6379\",\n\t\tPassword: \"\", // no password docs\n\t\tDB:       0,  // use default DB\n\t})\n\n\n\n\terr := rdb.Set(ctx, \"bike:1\", \"Process 134\", 0).Err()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(\"OK\")\n\n\tvalue, err := rdb.Get(ctx, \"bike:1\").Result()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"The name of the bike is %s\", value)\n\n}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "java",
      "code": "package io.redis.examples.async;\n\nimport io.lettuce.core.RedisClient;\nimport io.lettuce.core.api.async.RedisAsyncCommands;\nimport io.lettuce.core.api.StatefulRedisConnection;\n\nimport java.util.concurrent.CompletableFuture;\n\npublic class SetGetExample {\n\n    public void run() {\n        RedisClient redisClient = RedisClient.create(\"redis://localhost:6379\");\n\n        try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {\n            RedisAsyncCommands<String, String> asyncCommands = connection.async();\n\n\n            CompletableFuture<Void> setGetExample = asyncCommands.set(\"bike:1\", \"Process 134\")\n                    .thenCompose(res1 -> {\n                        System.out.println(res1); // >>> OK\n                        return asyncCommands.get(\"bike:1\");\n                    }).thenAccept(res2 -> {\n                        System.out.println(res2); // >>> Process 134\n                    }).toCompletableFuture();\n\n            setGetExample.join();\n        } finally {\n            redisClient.shutdown();\n        }\n    }\n}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "package io.redis.examples.reactive;\n\nimport io.lettuce.core.RedisClient;\nimport io.lettuce.core.api.reactive.RedisReactiveCommands;\nimport io.lettuce.core.api.StatefulRedisConnection;\n\nimport reactor.core.publisher.Mono;\n\npublic class SetGetExample {\n\n    public void run() {\n        RedisClient redisClient = RedisClient.create(\"redis://localhost:6379\");\n\n        try (StatefulRedisConnection<String, String> connection = redisClient.connect()) {\n            RedisReactiveCommands<String, String> reactiveCommands = connection.reactive();\n\n\n            Mono<Void> setGetExample = reactiveCommands.set(\"bike:1\", \"Process 134\")\n                    .doOnNext(res1 -> {\n                        System.out.println(res1); // >>> OK\n                    })\n                    .then(reactiveCommands.get(\"bike:1\"))\n                    .doOnNext(res2 -> {\n                        System.out.println(res2); // >>> Process 134\n                    })\n                    .then();\n\n            setGetExample.block();\n        } finally {\n            redisClient.shutdown();\n        }\n    }\n}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "package io.redis.examples;\n\nimport redis.clients.jedis.RedisClient;\n\n\npublic class SetGetExample {\n\n  public void run() {\n\n    RedisClient jedis = RedisClient.create(\"redis://localhost:6379\");\n\n    String status = jedis.set(\"bike:1\", \"Process 134\");\n\n    if (\"OK\".equals(status)) System.out.println(\"Successfully added a bike.\");\n\n    String value = jedis.get(\"bike:1\");\n\n    if (value != null) System.out.println(\"The name of the bike is: \" + value + \".\");\n\n\n    jedis.close();\n  }\n}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "javascript",
      "code": "import { createClient } from 'redis';\n\nconst client = createClient();\n\nclient.on('error', err => console.log('Redis Client Error', err));\n\nawait client.connect().catch(console.error);\n\nawait client.set('bike:1', 'Process 134');\nconst value = await client.get('bike:1');\nconsole.log(value);\n// returns 'Process 134'\n\nawait client.close();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "javascript",
      "code": "import assert from 'node:assert';\nimport { Redis } from 'ioredis';\n\nconst redis = new Redis();\n\n\nconst res1 = await redis.set('bike:1', 'Process 134');\nconsole.log(res1); // >>> OK\n\nconst res2 = await redis.get('bike:1');\nconsole.log(res2); // >>> Process 134\n\n\nredis.disconnect();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "import { createClient } from 'redis';\n\nconst client = createClient();\n\nclient.on('error', err => console.log('Redis Client Error', err));\n\nawait client.connect().catch(console.error);\n\nawait client.set('bike:1', 'Process 134');\nconst value = await client.get('bike:1');\nconsole.log(value);\n// returns 'Process 134'\n\nawait client.close();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "import assert from 'node:assert';\nimport { Redis } from 'ioredis';\n\nconst redis = new Redis();\n\n\nconst res1 = await redis.set('bike:1', 'Process 134');\nconsole.log(res1); // >>> OK\n\nconst res2 = await redis.get('bike:1');\nconsole.log(res2); // >>> Process 134\n\n\nredis.disconnect();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "php",
      "code": "<?php\nuse Predis\\Client as PredisClient;\n\nclass SetGetTest\n{\n    public function testSetGet() {\n        $r = new PredisClient([\n            'scheme'   => 'tcp',\n            'host'     => '127.0.0.1',\n            'port'     => 6379,\n            'password' => '',\n            'database' => 0,\n        ]);\n\n\n        $res1 = $r->set('bike:1', 'Process 134');\n        echo $res1 . PHP_EOL; // >>> OK\n\n        $res2 = $r->get('bike:1');\n        echo $res2 . PHP_EOL; // >>> Process 134\n\n    }\n}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "python",
      "code": "\"\"\"\nCode samples for data structure store quickstart pages:\n    https://redis.io/docs/latest/develop/get-started/data-store/\n\"\"\"\n\nimport redis\n\nr = redis.Redis(host=\"localhost\", port=6379, db=0, decode_responses=True)\n\nres = r.set(\"bike:1\", \"Process 134\")\nprint(res)\n# >>> True\n\nres = r.get(\"bike:1\")\nprint(res)\n# >>> \"Process 134\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "ruby",
      "code": "require 'redis'\n\nr = Redis.new\n\n\nres1 = r.set('bike:1', 'Process 134')\nputs res1 # >>> OK\n\nres2 = r.get('bike:1')\nputs res2 # >>> Process 134",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "rust",
      "code": "mod set_and_get_tests {\n    use redis::AsyncCommands;\n\n    async fn run() {\n        let mut r = match redis::Client::open(\"redis://127.0.0.1\") {\n            Ok(client) => match client.get_multiplexed_async_connection().await {\n                Ok(conn) => conn,\n                Err(e) => {\n                    println!(\"Failed to connect to Redis: {e}\");\n                    return;\n                }\n            },\n            Err(e) => {\n                println!(\"Failed to create Redis client: {e}\");\n                return;\n            }\n        };\n\n\n        if let Ok(res1) = r.set(\"bike:1\", \"Process 134\").await {\n            let res1: String = res1;\n            println!(\"{res1}\"); // >>> OK\n        }\n\n        if let Ok(res2) = r.get(\"bike:1\").await {\n            let res2: String = res2;\n            println!(\"{res2}\"); // >>> Process 134\n        }\n\n    }\n}",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "rust",
      "code": "mod set_and_get_tests {\n    use redis::Commands;\n\n    fn run() {\n        let mut r = match redis::Client::open(\"redis://127.0.0.1\") {\n            Ok(client) => match client.get_connection() {\n                Ok(conn) => conn,\n                Err(e) => {\n                    println!(\"Failed to connect to Redis: {e}\");\n                    return;\n                }\n            },\n            Err(e) => {\n                println!(\"Failed to create Redis client: {e}\");\n                return;\n            }\n        };\n\n\n        if let Ok(res1) = r.set(\"bike:1\", \"Process 134\") {\n            let res1: String = res1;\n            println!(\"{res1}\"); // >>> OK\n        }\n\n        if let Ok(res2) = r.get(\"bike:1\") {\n            let res2: String = res2;\n            println!(\"{res2}\"); // >>> Process 134\n        }\n\n    }\n}",
      "section_id": "examples"
    }
  ]
}
