- Usage:
GETEX key [ EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | persist ]
- Complexity:
- O(1)
- Since:
- 6.2.0
Get the value of key and optionally set its expiration.
GETEX is similar to GET, but is a write command with additional options.
Options
The GETEX command supports a set of options that modify its behavior:
EXseconds – Set the specified expire time, in seconds.PXmilliseconds – Set the specified expire time, in milliseconds.EXATtimestamp-seconds – Set the specified Unix time at which the key will expire, in seconds.PXATtimestamp-milliseconds – Set the specified Unix time at which the key will expire, in milliseconds.PERSIST– Remove the time to live associated with the key.
Examples
SET mykey "Hello"
GETEX mykey
TTL mykey
GETEX mykey EX 60
TTL mykey