EXPIREAT
Syntax
EXPIREAT key timestamp [NX | XX | GT | LT]
EXPIREAT sets the expiration time of a key as an absolute Unix timestamp (in seconds). After the expiry time has elapsed, the key will be automatically deleted.
The command returns 1 if the expiry was set or updated, and 0 if the expiration time was not changed. The command supports the following options:
- NX: Set the expiration only if the key does not already have an expiration time.
- XX: Set the expiration only if the key already has an expiration time.
- GT: Set the expiration only if the key already has an expiration time and the new expiration time is greater than the current expiration time.
- LT: Set the expiration only if the key already has an expiration time and the new expiration time is less than the current expiration time.
Examples
locahost:7379> SET k1 v1OK OKlocahost:7379> EXPIREAT k1 1740829942OK 1locahost:7379> EXPIREAT k1 1740829942 NXOK 0locahost:7379> EXPIREAT k1 1740829942 XXOK 0locahost:7379> EXPIREAT k1 1740829943 GTOK 0locahost:7379> EXPIREAT k1 1740829942 LTOK 1