SPEXPIREAT
SPEXPIREAT key unix-time-milliseconds [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 SEXPIREAT, but the absolute Unix time at which the members expire is specified in milliseconds instead of seconds.
Required arguments
key
The name of the key that holds the set.
unix-time-milliseconds
The expiration time, as a Unix timestamp in milliseconds. 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> SPEXPIREAT myset 4102444800000 MEMBERS 1 member1
1) (integer) 1
redis> SPEXPIREAT myset 4102444800000 XX MEMBERS 1 member2
1) (integer) 0
redis> SPEXPIRETIME myset MEMBERS 2 member1 member2
1) (integer) 4102444800000
2) (integer) -1
Details
See SEXPIRE for how member expiration interacts with other set commands. Use SPEXPIRETIME 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 | SEXPIREAT | SADDEX | STTL | SPTTL | SEXPIRETIME | SPEXPIRETIME | SPERSIST