pexpire
PEXPIRE milliseconds
Automatically delete the key after the specified time (milliseconds)
Usage: pexpire key milliseconds [type].
type is one of string/list/set/zset/hash/stream.
The type argument was added in ent811. Please use it.
Example
| Command> | set key value |
| Result> | 1 |
| Command> | pexpire key 5000 string |
| Result> | 1 |
| Command> | pttl key string |
| Result> | 3546 |
| Command> | pttl key string |
| Result> | -2 |
| Command> | get key |
| Result> | (nil) |
Overwriting with SET removes the expire time
After a pexpire time is set, if SET is run on the same key, the expire time is removed and the key is not deleted.
Commands like this are set, getset.
Commands such as incr, lpush, sadd, zadd, and hset do not remove the expire time.
Example
| Command> | set key value |
| Result> | 1 |
| Command> | pexpire key 5000 string |
| Result> | 1 |
| Command> | pttl key string |
| Result> | 3546 |
| Command> | set key new_value |
| Result> | 1 |
| Command> | pttl key string |
| Result> | -1 |
| Command> | get key |
| Result> | new_value |
RENAME does not remove the expire time
Changing the key name does not remove the expire time.
Example
| Command> | set key value |
| Result> | 1 |
| Command> | pexpire key 5000 string |
| Result> | 1 |
| Command> | rename key new_key string |
| Result> | OK |
| Command> | pttl key string |
| Result> | -2 |
| Command> | get key |
| Result> | (nil) |
Syntax
PEXPIRE key milliseconds [type]
- Available since version 2.6.0.
- Time complexity is O(1).
- The type argument was added in ent811.