Skip to content

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 v1
OK OK
locahost:7379> EXPIREAT k1 1740829942
OK 1
locahost:7379> EXPIREAT k1 1740829942 NX
OK 0
locahost:7379> EXPIREAT k1 1740829942 XX
OK 0
locahost:7379> EXPIREAT k1 1740829943 GT
OK 0
locahost:7379> EXPIREAT k1 1740829942 LT
OK 1