{
  "schema_version": 2,
  "id": "commands/hsetex",
  "title": "HSETEX",
  "url": "https://redis.io/docs/latest/commands/hsetex/",
  "summary": "Set the value of one or more fields of a given hash key, and optionally set their expiration.",
  "since": "8.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-06-15T06:26:34-07:00",
  "page_type": "content",
  "content_hash": "0e4fcf718e2af444bd6790f0f4545d8a83a7a776e40954ac9fe9e4fca8fa5ae5",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "Set the value of one or more fields of a given hash key and optionally\nset their expiration time or time-to-live (TTL). If the given key already holds a value, it is overwritten and any previous TTLs associated with the key are discarded."
    },
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key that holds the hash.\n\n</details>\n\n<details open><summary><code>FIELDS numfields field value [field value ...]</code></summary>\n\nThe hash field-value pairs to set. `numfields` is the number of fields, followed by that many field-value pairs.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "The following options modify the command's behavior. The `EX`, `PX`, `EXAT`, `PXAT`, and `KEEPTTL` options are mutually exclusive.\n\n<details open><summary><code>FNX</code></summary>\n\nOnly set the fields if none of them already exist. `FNX` and `FXX` are mutually exclusive.\n\n</details>\n\n<details open><summary><code>FXX</code></summary>\n\nOnly set the fields if all of them already exist.\n\n</details>\n\n<details open><summary><code>EX seconds</code></summary>\n\nSet the specified expiration time, in seconds.\n\n</details>\n\n<details open><summary><code>PX milliseconds</code></summary>\n\nSet the specified expiration time, in milliseconds.\n\n</details>\n\n<details open><summary><code>EXAT unix-time-seconds</code></summary>\n\nSet the specified Unix time, in seconds, at which the fields will expire.\n\n</details>\n\n<details open><summary><code>PXAT unix-time-milliseconds</code></summary>\n\nSet the specified Unix time, in milliseconds, at which the fields will expire.\n\n</details>\n\n<details open><summary><code>KEEPTTL</code></summary>\n\nRetain the TTL associated with the fields.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "[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* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no fields were set.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if all the fields wereset.\n\n**RESP3:**\n\nOne of the following:\n* [Integer reply](../../develop/reference/protocol-spec#integers): `0` if no fields were set.\n* [Integer reply](../../develop/reference/protocol-spec#integers): `1` if all the fields wereset."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "redis> HSETEX mykey EXAT 1740470400 FIELDS 2 field1 \"Hello\" field2 \"World\"\n(integer) 1\nredis> HTTL mykey FIELDS 2 field1 field2\n1) (integer) 55627\n2) (integer) 55627\nredis> HSETEX mykey FNX EX 60 FIELDS 2 field1 \"Hello\" field2 \"World\"\n(integer) 0\nredis> HSETEX mykey FXX EX 60 KEEPTTL FIELDS 2 field1 \"hello\" field2 \"world\"\n(error) ERR Only one of EX, PX, EXAT, PXAT or KEEPTTL arguments can be specified\nredis> HSETEX mykey FXX KEEPTTL FIELDS 2 field1 \"hello\" field2 \"world\"\n(integer) 1\nredis> HTTL mykey FIELDS 2 field1 field2\n1) (integer) 55481\n2) (integer) 55481",
      "section_id": "examples"
    }
  ]
}
