GETEX

Syntax

  1. GETEX key [EX seconds | PX milliseconds | EXAT unix-time-seconds | PXAT unix-time-milliseconds | PERSIST]

Time complexity: O(1)

ACL categories: @write, @string, @fast

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:

  • EX seconds — Set the specified expire time, in seconds.
  • PX milliseconds — Set the specified expire time, in milliseconds.
  • EXAT timestamp-seconds — Set the specified Unix time at which the key will expire, in seconds.
  • PXAT timestamp-milliseconds — Set the specified Unix time at which the key will expire, in milliseconds.
  • PERSIST — Remove the time to live associated with the key.

When supplied with no options, GETEX is equivalent to GET.

Return

Bulk string reply: the value of key, or nil when key does not exist.

Examples

  1. dragonfly> SET mykey "Hello"
  2. "OK"
  3. dragonfly> GETEX mykey
  4. "Hello"
  5. dragonfly> TTL mykey
  6. (integer) -1
  7. dragonfly> GETEX mykey EX 60
  8. "Hello"
  9. dragonfly> TTL mykey
  10. (integer) 60