EXPIRE
Since 1.1.0Keys
Syntax
EXPIRE key seconds [NX | XX | GT | LT]Makes key expire after seconds. A zero or negative time deletes the key at once.
Options
| Option | Set the expiry only if |
|---|---|
NX | the key has none |
XX | the key has one |
GT | the new expiry is later than the current one |
LT | the new expiry is earlier than the current one |
A key without an expiry counts as never expiring: GT does not set one, LT does.
Reply
1if the expiry was set.0if the key does not exist, or the condition was not met.ERR value is not an integer or out of rangeifsecondsis not an integer.
Examples
> SET a 1
OK
> EXPIRE a 100
(integer) 1
> EXPIRE a 50 GT
(integer) 0
> EXPIRE a 200 GT
(integer) 1
> TTL a
(integer) 200
> SET p 1
OK
> EXPIRE p 100 GT
(integer) 0
> EXPIRE p 100 LT
(integer) 1