{
  "schema_version": 2,
  "id": "commands/pexpire",
  "title": "PEXPIRE",
  "url": "https://redis.io/docs/latest/commands/pexpire/",
  "summary": "Sets the expiration time of a key in milliseconds.",
  "since": "2.6.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-18T09:48:32+01:00",
  "page_type": "content",
  "content_hash": "50686052d4f43b27ca0d66dd5b66a8299f8fd4561809a84787b44f8817eb6c82",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "This command works exactly like [`EXPIRE`](https://redis.io/docs/latest/commands/expire) but the time to live of the key is\nspecified in milliseconds instead of seconds."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key to set a timeout on.\n\n</details>\n\n<details open><summary><code>milliseconds</code></summary>\n\nThe timeout, in milliseconds.\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>NX</code></summary>\n\nSet expiry only when the key has no expiry.\n\n</details>\n\n<details open><summary><code>XX</code></summary>\n\nSet expiry only when the key has an existing expiry.\n\n</details>\n\n<details open><summary><code>GT</code></summary>\n\nSet expiry only when the new expiry is greater than the current one. A non-volatile key is treated as an infinite TTL for the purpose of `GT`.\n\n</details>\n\n<details open><summary><code>LT</code></summary>\n\nSet expiry only when the new expiry is less than the current one. A non-volatile key is treated as an infinite TTL for the purpose of `LT`.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> SET mykey \"Hello\"\nOK\nredis> PEXPIRE mykey 1500\n(integer) 1\nredis> TTL mykey\n(integer) 2\nredis> PTTL mykey\n(integer) 1500\nredis> PEXPIRE mykey 1000 XX\n(integer) 1\nredis> TTL mykey\n(integer) 1\nredis> PEXPIRE mykey 1000 NX\n(integer) 0\nredis> TTL mykey\n(integer) 1"
    },
    {
      "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* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if the timeout was not set. For example, if the key doesn't exist, or the operation skipped because of the provided arguments.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if the timeout was set.\n\n**RESP3:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if the timeout was not set. For example, if the key doesn't exist, or the operation skipped because of the provided arguments.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if the timeout was set."
    }
  ],
  "examples": []
}
