Skip to content

GETEX

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.
localhost:7379> SET k v
OK
localhost:7379> GETEX k EX 1000
OK "v"
localhost:7379> TTL k
OK 996
localhost:7379> GETEX k PX 200000
OK "v"
localhost:7379> GETEX k EXAT 1772377267
OK "v"
localhost:7379> GETEX k PXAT 1772377267000
OK "v"
localhost:7379> GETEX k PERSIST
OK "v"
localhost:7379> EXPIRETIME k
OK -1