Of course the actual implementation is more complicated than this, but this is the main idea.Īnd the source code for the active expiration cycle can be found here: This does not affect the expire behavior, it just adds "garbage collection" of expired keys. It just reads random keys all the time, and when an expired key is touched it is deleted based on the lazy mechanism. So Redis adds a second layer of random active expiration. But the problem is that if a key is never touched, it just takes up memory for no reason. When reading an object, we check its expiration timestamp, and if it's in the past, we return nothing, and delete the object while we're at it. Lazy expiration means that you don't actually expire the objects until they are read. Now, the expiration mechanism itself is semi-lazy. Unless you set the object to expire, that time is "never". In short - for each redis object, there is an expiration time.
0 Comments
Leave a Reply. |