setex
SETEX
Delete data after a given time: specify seconds
The data is deleted after the specified number of seconds.
This is useful when storing data that has an expiration time.
Usage is SETEX key seconds value.
Example
| Command> | setex key 5 value
|
| Result> | OK
|
| Command> | ttl key
|
| Result> | 2 remaining time in seconds
|
| Command> | get key
|
| Result> | (nil) data deleted after 5 seconds
|
View animation
|
TTL reports the remaining time in seconds.
|
Syntax
SETEX key seconds value
- Available since version 2.0.0.
- Time complexity is O(1).