Redis expand chapter ---- expiration policy

Redis expiration policies

Redis expires in: all data structures in Redis can set the expiration time, the time comes it will be automatically deleted.
Redis is single-threaded, how to ensure the line to ensure that when you delete the expired key reader does not appear Caton?

1, a collection of key expired

Redis will each set up a key expiration time into a separate dictionary, Redis will regularly traverse the dictionary to remove expired key
deletion policy: mainly regularly delete (focus) and inert deleted (fragmented process)
inert delete: query key has expired when the client access key, it will delete expired

2, regular scanning policies

Redis default 10 times per second, greedy strategy used when scanning the following steps:

  1. From Expired dictionary randomly selected 20 key
  2. 20 Delete key in the key has expired
  3. If the ratio is more than 1/4 expired key, then repeat steps (1)
    In order to ensure that there is a thread stuck phenomenon, the algorithm increases the upper limit of the scan time, the default will not exceed 25ms
    Note:
    key in the settings redis expired when the time should avoid a large number of key expiration occurs at the same time, a large number of key expired the same time will lead to read and write Caton.
    Another case Caton is due when you delete key memory manager frequently reclaim memory page, which will have some cpu consumption.
    If you must delete key at the same time, the expiration time should be given a random set range, randomization time is about to expire

3, the nodes from the expiration policy

In Redis does not expire from node scanning, processing expired from the node is passive, will add a del command in the AOF file expires when the master node key, all synchronized to the slave nodes

Guess you like

Origin blog.csdn.net/alvin_666/article/details/90741408