Redis Command SETEX key Seconds value
SETEX
The SETEX command sets a string value with a key and seconds. The data is deleted after the specified number of seconds.
It is useful for storing data with an expiration time.
- Available version: version 2.0.0 and later
- Logical processing time complexity: O(1)
It behaves the same as the following two commands.
SET mykey value
EXPIRE mykey seconds
SETEX usage
The usage is as follows.
SETEX [key] [seconds] [value]
When creating a key to store a string value, you can also set a timeout. The key is deleted after the timeout period has passed. It has the same effect as the following two commands.
Data is deleted after the specified time: specify in seconds.
Data is deleted after the specified number of seconds.
It is useful for storing data with an expiration time.
The usage is SETEX key seconds value.
Example Command> setex key 5 value Result> OK Command> ttl key Result> 2 shows the remaining time in seconds Command> get key Result> (nil) data was deleted after 5 seconds View animation
The TTL command shows the remaining time in seconds.