Syntax
Parameters
The name of the key to set.
The string value to store.
Optional flag to enable a time-to-live. Must be followed by a non-negative integer.
Expiry duration in seconds from the current time. Must be
>= 0. Required when EX is provided.Return value
ReturnsOK on success.
Errors
| Condition | Error message |
|---|---|
| Wrong number of arguments | (error) wrong number of arguments for 'SET' |
seconds is negative | Returns (nil) — the EX clause is rejected and no key is written |
Examples
Notes
SET without EX stores expires_at = 0, which means the key has no expiration. If the key previously had a TTL, that TTL is cleared.Every
SET call is immediately appended to the append-only file (AOF), so the write is durable before the command returns.