{
  "schema_version": 2,
  "id": "commands/spexpireat",
  "title": "SPEXPIREAT",
  "url": "https://redis.io/docs/latest/commands/spexpireat/",
  "summary": "Set expiry for set member using an absolute Unix timestamp (milliseconds)",
  "since": "8.12.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-11-23T06:19:08-08:00",
  "page_type": "content",
  "content_hash": "23f0a404d0bdc6a071debfe22242709c301a2047629ee81ad18491ac2fe5afcc",
  "sections": [
    {
      "id": "overview",
      "title": "Overview",
      "role": "overview",
      "text": "This command works like [`SEXPIREAT`](https://redis.io/docs/latest/commands/sexpireat), but the absolute Unix time at which the members expire 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 that holds the set.\n\n</details>\n\n<details open><summary><code>unix-time-milliseconds</code></summary>\n\nThe expiration time, as a Unix timestamp in milliseconds. A time in the past removes the members immediately.\n\n</details>\n\n<details open><summary><code>MEMBERS nummembers member [member ...]</code></summary>\n\nThe set members to specify expiration for. `nummembers` is the number of members, followed by that many member names.\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\nFor each specified member, apply the expiration only when the member has no expiration.\n\n</details>\n\n<details open><summary><code>XX</code></summary>\n\nFor each specified member, apply the expiration only when the member has an existing expiration.\n\n</details>\n\n<details open><summary><code>GT</code></summary>\n\nFor each specified member, apply the expiration only when the new expiration is greater than the current one. A member with no expiration is treated as having an infinite TTL for the purposes of `GT`.\n\n</details>\n\n<details open><summary><code>LT</code></summary>\n\nFor each specified member, apply the expiration only when the new expiration is less than the current one. A member with no expiration is treated as having an infinite TTL for the purposes of `LT`.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "[code example]"
    },
    {
      "id": "details",
      "title": "Details",
      "role": "content",
      "text": "See [`SEXPIRE`](https://redis.io/docs/latest/commands/sexpire#details) for how member expiration interacts with other set commands. Use [`SPEXPIRETIME`](https://redis.io/docs/latest/commands/spexpiretime) to read back the expiration time of a member."
    },
    {
      "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=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> | <span title=\"Not supported\">&#x274c; Standard</span><br /><span title=\"Not supported\"><nobr>&#x274c; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nOne of the following:\n* [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays). For each member:\n    - [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `-2` if no such member exists in the set, or the key does not exist.\n    - [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `0` if the specified `NX`, `XX`, `GT`, or `LT` condition was not met.\n    - [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `1` if the expiration time was set or updated.\n    - [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `2` if the member was removed because the specified time is in the past.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors):\n    - if parsing failed, mandatory arguments are missing, unknown arguments are specified, or argument values are of the wrong type or out of range.\n    - if the key exists but is not a set.\n\n**RESP3:**\n\nOne of the following:\n* [Array reply](https://redis.io/docs/latest/develop/reference/protocol-spec#arrays). For each member:\n    - [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `-2` if no such member exists in the set, or the key does not exist.\n    - [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `0` if the specified `NX`, `XX`, `GT`, or `LT` condition was not met.\n    - [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `1` if the expiration time was set or updated.\n    - [Integer reply](https://redis.io/docs/latest/develop/reference/protocol-spec#integers): `2` if the member was removed because the specified time is in the past.\n* [Simple error reply](https://redis.io/docs/latest/develop/reference/protocol-spec#simple-errors):\n    - if parsing failed, mandatory arguments are missing, unknown arguments are specified, or argument values are of the wrong type or out of range.\n    - if the key exists but is not a set."
    },
    {
      "id": "see-also",
      "title": "See also",
      "role": "related",
      "text": "[`SEXPIRE`](https://redis.io/docs/latest/commands/sexpire) | [`SPEXPIRE`](https://redis.io/docs/latest/commands/spexpire) | [`SEXPIREAT`](https://redis.io/docs/latest/commands/sexpireat) | [`SADDEX`](https://redis.io/docs/latest/commands/saddex) | [`STTL`](https://redis.io/docs/latest/commands/sttl) | [`SPTTL`](https://redis.io/docs/latest/commands/spttl) | [`SEXPIRETIME`](https://redis.io/docs/latest/commands/sexpiretime) | [`SPEXPIRETIME`](https://redis.io/docs/latest/commands/spexpiretime) | [`SPERSIST`](https://redis.io/docs/latest/commands/spersist)"
    },
    {
      "id": "related-topics",
      "title": "Related topics",
      "role": "related",
      "text": "- [Set member expiration](https://redis.io/docs/latest/develop/data-types/sets#member-expiration)"
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "redis",
      "code": "redis> SADD myset member1 member2\n(integer) 2\nredis> SPEXPIREAT myset 4102444800000 MEMBERS 1 member1\n1) (integer) 1\nredis> SPEXPIREAT myset 4102444800000 XX MEMBERS 1 member2\n1) (integer) 0\nredis> SPEXPIRETIME myset MEMBERS 2 member1 member2\n1) (integer) 4102444800000\n2) (integer) -1",
      "section_id": "examples"
    }
  ]
}
