Absolute deadline coordination
Coordinate expiration with an externally calculated deadline shared across services.
Redis · Command
Sets a key's expiration to an absolute Unix timestamp in seconds. Optional NX, XX, GT, or LT conditions control when the deadline may be changed.
EXPIREAT assigns a key an expiration deadline expressed as an absolute Unix timestamp in seconds rather than as a relative duration. Optional conditions can restrict whether Redis changes the deadline; a timestamp in the past removes the key immediately.
EXPIREAT key unix-time-seconds [NX | XX | GT | LT]| Name | Type | Description |
|---|---|---|
key | key | The key whose expiration is being changed. |
unix-time-seconds | integer | Absolute expiration time as a Unix timestamp in seconds. |
condition | enum | Optional mutually exclusive condition: NX, XX, GT, or LT. |
Integer 1 if the timeout was set; integer 0 if it was not set, such as when the key does not exist or a supplied condition prevents the operation.
SET session:user:42 "active"
EXPIREAT session:user:42 4102444800
TTL session:user:42Sets a key, assigns it an absolute expiration time in Unix seconds, then checks its remaining TTL.
Coordinate expiration with an externally calculated deadline shared across services.
Restore or migrate data while preserving an expiration time represented as an epoch timestamp.
Prevent a refresh from shortening or extending a deadline by using LT or GT.
EXPIREAT sets a key's expiration using an absolute Unix timestamp in seconds. It returns 1 when the expiration is set and 0 when the key is missing or the requested condition prevents the change.
Follow-up: How would you apply a deadline only if the key already has one? Use the XX option, which skips the update when the key is persistent.
NX applies the deadline only when the key currently has no expiration. XX applies it only when the key already has an expiration; these conditional modes cannot be combined.
Follow-up: Which option ensures a new deadline is later than the current one? GT; a persistent key is treated as having an infinite TTL for this comparison.
The timestamp is measured in seconds since January 1, 1970, unlike EXPIRE, which accepts a relative number of seconds. A deadline in the past deletes the key immediately.
Follow-up: What operational event differs for a past timestamp? Redis deletes the key and generates a del event rather than an expire event.
EXPIREPEXPIREATEXPIRETIMETTLPERSIST