GETEX

Since 1.1.0Strings

Syntax

GETEX key [EX s | PX ms | EXAT ts | PXAT ts | PERSIST]
  • Flags: fast, write
  • ACL categories: @fast, @string, @write
  • Arity: -2

Returns the string at key and, optionally, changes its expiry.

Options

OptionEffect
EX seconds, PX millisecondsExpire the key after this long.
EXAT unix-seconds, PXAT unix-millisecondsExpire the key at this time.
PERSISTRemove the key's expiry.

Without an option, GETEX is GET. Only one option can be given: two are ERR syntax error. A time is checked as SET checks it, EXAT 0 and PXAT 0 included. An EXAT or PXAT that has passed deletes the key at once, and the key's keyspace event is del, as in Redis. On a key that is not there, it answers nil whatever the time. These are since 1.2.1: 1.2.0 read the first option only and passed over the rest.

Reply

  • The value, or nil if the key does not exist; a missing key is not created.

Examples

> SET g v EX 100
OK
> GETEX g PERSIST
"v"
> TTL g
(integer) -1
> GETEX g PX 5000
"v"
> PTTL g
(integer) 5000