Home > Database > Redis > What does redis expiration policy mean?

What does redis expiration policy mean?

hzc
Release: 2020-06-28 14:37:25
Original
3556 people have browsed it

The expiration strategy of Redis refers to how Redis should handle it when the cached key in Redis expires. Generally, there are three processing methods: scheduled expiration, lazy expiration, and periodic expiration.

What does redis expiration policy mean?

The expiration policy of Redis refers to how Redis handles it when the cached key in Redis expires.

  • Timed expiration: Each key with an expiration time needs to create a timer, which will be cleared immediately after the expiration time. This strategy can immediately clear expired data and is very memory-friendly; however, it will occupy a large amount of CPU resources to process expired data, thus affecting the cache response time and throughput.

  • Lazy expiration: Only when a key is accessed, it will be judged whether the key has expired, and it will be cleared when it expires. This strategy can save CPU resources to the maximum extent, but it is very unfriendly to memory. In extreme cases, a large number of expired keys may not be accessed again, thus not being cleared and occupying a large amount of memory.

  • Periodic expiration: Every certain period of time, a certain number of keys in the expires dictionary of a certain number of databases will be scanned, and the expired keys will be cleared. This strategy is a compromise between the first two. By adjusting the time interval of scheduled scans and the limited time consumption of each scan, the optimal balance between CPU and memory resources can be achieved under different circumstances.

(The expires dictionary will save the expiration time data of all keys with expiration time set, where key is a pointer to a key in the key space, and value is the millisecond of the key. The expiration time represented by the precision UNIX timestamp. The key space refers to all the keys saved in the Redis cluster.)

Redis uses both lazy expiration and periodic expiration strategies.

Recommended tutorial: "Redis Tutorial"

The above is the detailed content of What does redis expiration policy mean?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template