GETEX
Syntax
Section titled “Syntax”GETEX key [EX seconds] [PX milliseconds] [EXAT timestamp-seconds] [PXAT timestamp-milliseconds] [PERSIST]
GETEX gets the value of key and optionally set its expiration. The behavior of the command is similar to the GET command with the addition of the ability to set an expiration on the key.
The command returns (nil) if the key does not exist. The command supports the following options:
- EX seconds: Set the expiration to seconds from now.
- PX milliseconds: Set the expiration to milliseconds from now.
- EXAT timestamp: Set the expiration to a Unix timestamp.
- PXAT timestamp: Set the expiration to a Unix timestamp in milliseconds.
- PERSIST: Remove the expiration from the key.
Examples
Section titled “Examples”localhost:7379> SET k vOKlocalhost:7379> GETEX k EX 1000OK "v"localhost:7379> TTL kOK 996localhost:7379> GETEX k PX 200000OK "v"localhost:7379> GETEX k EXAT 1772377267OK "v"localhost:7379> GETEX k PXAT 1772377267000OK "v"localhost:7379> GETEX k PERSISTOK "v"localhost:7379> EXPIRETIME kOK -1