{
  "schema_version": 2,
  "id": "commands/getex",
  "title": "GETEX",
  "url": "https://redis.io/docs/latest/commands/getex/",
  "summary": "Returns the string value of a key after setting its expiration time.",
  "since": "6.2.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": "04b575ff5fdafad03c10fc99689041a7bacd02b3693f469719ddd16c4415bfa3",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Get the value of `key` and optionally set its expiration.\n`GETEX` is similar to [`GET`](https://redis.io/docs/latest/commands/get), but is a write command with additional options."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key to retrieve.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "The following options modify the command's behavior. They are mutually exclusive.\n\n<details open><summary><code>EX seconds</code></summary>\n\nSet the specified expire time, in seconds.\n\n</details>\n\n<details open><summary><code>PX milliseconds</code></summary>\n\nSet the specified expire time, in milliseconds.\n\n</details>\n\n<details open><summary><code>EXAT unix-time-seconds</code></summary>\n\nSet the specified Unix time at which the key will expire, in seconds.\n\n</details>\n\n<details open><summary><code>PXAT unix-time-milliseconds</code></summary>\n\nSet the specified Unix time at which the key will expire, in milliseconds.\n\n</details>\n\n<details open><summary><code>PERSIST</code></summary>\n\nRemove the time to live associated with the key. See [`PERSIST`](https://redis.io/docs/latest/commands/persist).\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> SET mykey \"Hello\"\nOK\nredis> GETEX mykey\n\"Hello\"\nredis> TTL mykey\n(integer) -1\nredis> GETEX mykey EX 60\n\"Hello\"\nredis> TTL mykey\n(integer) 60"
    },
    {
      "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> | \\*Not supported for HyperLogLog. |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\n[Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the value of `key`\n[Nil reply](../../develop/reference/protocol-spec#bulk-strings): if `key` does not exist.\n\n**RESP3:**\n\n[Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): the value of `key`\n[Null reply](../../develop/reference/protocol-spec#nulls): if `key` does not exist."
    }
  ],
  "examples": []
}
