SEXPIREAT
SEXPIREAT key unix-time-seconds [NX | XX | GT | LT] MEMBERS nummembers member [member ...]
- Available since:
- Redis Open Source 8.12.0
- Time complexity:
- O(N) where N is the number of specified members
- ACL categories:
-
@write,@set,@fast, - Compatibility:
- Redis Software and Redis Cloud compatibility
This command works like SEXPIRE, but instead of a TTL in seconds, it takes the absolute Unix time at which the members expire, in seconds since the Unix epoch.
Required arguments
key
The name of the key that holds the set.
unix-time-seconds
The expiration time, as a Unix timestamp in seconds. A time in the past removes the members immediately.
MEMBERS nummembers member [member ...]
The set members to specify expiration for. nummembers is the number of members, followed by that many member names.
Optional arguments
The following options modify the command's behavior. They are mutually exclusive.
NX
For each specified member, apply the expiration only when the member has no expiration.
XX
For each specified member, apply the expiration only when the member has an existing expiration.
GT
For 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.
LT
For 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.
Examples
redis> SADD myset member1 member2
(integer) 2
redis> SEXPIREAT myset 4102444800 MEMBERS 1 member1
1) (integer) 1
redis> SEXPIRETIME myset MEMBERS 2 member1 member2
1) (integer) 4102444800
2) (integer) -1
redis> SEXPIREAT myset 1 MEMBERS 1 member2
1) (integer) 2
redis> SMEMBERS myset
1) "member1"
Details
See SEXPIRE for how member expiration interacts with other set commands. Use SEXPIRETIME to read back the expiration time of a member.
Redis Software and Redis Cloud compatibility
| Redis Software |
Redis Cloud |
Notes |
|---|---|---|
| ❌ Standard |
❌ Standard |
Return information
One of the following:
- Array reply. For each member:
- Integer reply:
-2if no such member exists in the set, or the key does not exist. - Integer reply:
0if the specifiedNX,XX,GT, orLTcondition was not met. - Integer reply:
1if the expiration time was set or updated. - Integer reply:
2if the member was removed because the specified time is in the past.
- Integer reply:
- Simple error reply:
- if parsing failed, mandatory arguments are missing, unknown arguments are specified, or argument values are of the wrong type or out of range.
- if the key exists but is not a set.
See also
SEXPIRE | SPEXPIRE | SPEXPIREAT | SADDEX | STTL | SPTTL | SEXPIRETIME | SPEXPIRETIME | SPERSIST