Back to Redis

SETEX

content/commands/setex.md

latest1.1 KB
Original Source

Set key to hold the string value and set key to timeout after a given number of seconds. This command is equivalent to:

SET key value EX seconds

An error is returned when seconds is invalid.

Examples

{{% redis-cli %}} SETEX mykey 10 "Hello" TTL mykey GET mykey {{% /redis-cli %}}

See also

[TTL]({{< relref "/commands/ttl" >}})

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> | |

Return information

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

Simple string reply: OK.

-tab-sep-

Simple string reply: OK.

{{< /multitabs >}}