Redis already has many commands for this:
- EXPIRE : set the timeout on the key.
- EXPIREAT : as before, but takes the absolute Unix timestamp (seconds since January 1, 1970).
- TTL : returns the remaining time for the life of a key with a timeout
One important thing you should know about Redis expiration: the timeout value is cleared only when the key is deleted or overwritten with SET or GETSET. All other commands (INCR, LPUSH, HMSET, ...) will never change the initial timeout.
Absolute expiration is a Redis built-in function using EXPIRE. To implement slip acceleration , you just need to reset to set the timeout value after each command.
The main way to do this could be
MULTI GET MYKEY EXPIRE MYKEY 60 EXEC
source share