{
  "schema_version": 2,
  "id": "commands/psetex",
  "title": "PSETEX",
  "url": "https://redis.io/docs/latest/commands/psetex/",
  "summary": "Sets both string value and expiration time in milliseconds of a key. The key is created if it doesn't exist.",
  "since": "2.6.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": "1ef4cf974c69cda7e2beaee3383b03aaae1dd320f157d9aea3ca2f06f476948d",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "`PSETEX` works exactly like [`SETEX`](https://redis.io/docs/latest/commands/setex) with the sole difference that the expire\ntime is specified 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.\n\n</details>\n\n<details open><summary><code>milliseconds</code></summary>\n\nThe time to live, in milliseconds.\n\n</details>\n\n<details open><summary><code>value</code></summary>\n\nThe value to set.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "redis> PSETEX mykey 1000 \"Hello\"\nOK\nredis> PTTL mykey\n(integer) 1000\nredis> GET mykey\n\"Hello\""
    },
    {
      "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[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`.\n\n**RESP3:**\n\n[Simple string reply](../../develop/reference/protocol-spec#simple-strings): `OK`."
    }
  ],
  "examples": []
}
