SETEX
SETEX key seconds value
- Group
- String
- Complexity
- O(1)
- Arity
- 4 (exactly, counting the command name)
- Flags
- write
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
SETEX stores value at key and makes it expire after seconds, in one
step. It is the same as SET key value EX seconds. Any existing value, of any
type, is overwritten.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Always | Simple string OK |
Simple string OK |
Errors:
ERR value is not an integer or out of rangewhensecondsis not an integer.ERR invalid expire time in 'setex' commandwhensecondsis zero, negative or too large.
Examples
Section titled “Examples”127.0.0.1:6379> SETEX session:9 600 "user:9"OK127.0.0.1:6379> TTL session:9(integer) 600127.0.0.1:6379> SETEX session:9 0 "user:9"(error) ERR invalid expire time in 'setex' commandCompatibility
Section titled “Compatibility”Same as Redis 7 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.