A brief discussion on how to deal with cache expiration and memory occupied by cache in Redis? The following article will take you through the cache expiration processing strategy and memory elimination mechanism in Redis. I hope it will be helpful to you!
The expired key cache has expired, but the server's memory will still be occupied. This is because of the two deletion strategies that redis is based on.
Redis has two strategies:
(Active) Regular deletion
(Passive) Lazy deletion
So, although the key has expired, as long as it is not cleared by redis, the memory will still be occupied. [Related recommendations: Redis Video Tutorial]
When the memory is full, you can use the hard disk to save it, but it is meaningless because the hard disk is not as fast as the memory and will affect the performance of redis.
So, when the memory is full, redis provides a cache elimination mechanism: MEMORY MANAGEMENT
maxmemory
: When the memory usage rate reaches, the cache starts to be cleaned
* noeviction:旧缓存永不过期,新缓存设置不了,返回错误 * allkeys-lru:清除最少用的旧缓存,然后保存新的缓存(推荐使用) * allkeys-random:在所有的缓存中随机删除(不推荐) * volatile-lru:在那些设置了expire过期时间的缓存中,清除最少用的旧缓存,然后保存新的缓存 * volatile-random:在那些设置了expire过期时间的缓存中,随机删除缓存 * volatile-ttl:在那些设置了expire过期时间的缓存中,删除即将过期的`
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of A brief discussion on how to deal with cache expiration and memory occupied by cache in Redis?. For more information, please follow other related articles on the PHP Chinese website!