Back to Redis

GETEX

content/commands/getex.md

latest1.8 KB
Original Source

Get the value of key and optionally set its expiration. GETEX is similar to [GET]({{< relref "/commands/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]({{< relref "/commands/persist" >}}) -- Remove the time to live associated with the key.

Examples

{{% redis-cli %}} SET mykey "Hello" GETEX mykey TTL mykey GETEX mykey EX 60 TTL mykey {{% /redis-cli %}}

Redis Software and Redis Cloud compatibility

| Redis Software | Redis Cloud | <span style="min-width: 9em; display: table-cell">Notes</span> | |:----------------------|:-----------------|:------| | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active*</nobr></span> | <span title="Supported">✅ Standard</span> <span title="Supported"><nobr>✅ Active-Active*</nobr></span> | *Not supported for HyperLogLog. |

Return information

{{< multitabs id="getex-return-info" tab1="RESP2" tab2="RESP3" >}}

Bulk string reply: the value of key Nil reply: if key does not exist.

-tab-sep-

Bulk string reply: the value of key Null reply: if key does not exist.

{{< /multitabs >}}