In this regard, you can search for Redis expiration strategy. There are many related articles. I only understand and use Redis and have not studied the principles in depth.
This article has instructions: http://www.cppblog.com/richbirdandy/archive/2011/11/29/161184.html
The above three ways to delete expired keys. The second way is to regularly delete a certain proportion of keys. The first way is "delete while reading" to ensure that expired keys will not be accessed. The third way is to delete expired keys when the memory is exceeded. Violent means during setting. From this we can also see the ingenuity of redis design,
In this regard, you can search for Redis expiration strategy. There are many related articles. I only understand and use Redis and have not studied the principles in depth.
This article has instructions: http://www.cppblog.com/richbirdandy/archive/2011/11/29/161184.html
Lazy deletion and regular deletion, please see "Redis Design and Implementation" for detailed explanation