How it works...
When a timeout is set on a Redis key, the expiration time for the key will be stored as an absolute UNIX timestamp. Therefore, even if the Redis Server is down for some time, the expiration timestamp won't be lost and the key will still expire when the server is up again and the clock has passed the UNIX timestamp.
When a key has expired and the client tries to access it, Redis will delete the key from memory immediately. The way Redis deletes a key is known as expiring passively. What if a key has expired but it will never be accessed again? Redis also actively deletes expired keys by running a probabilistic algorithm periodically. Specifically, Redis randomly picks 20 keys associated with the timeout. Expired keys will be ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access