redis expiration policy analysis and memory elimination mechanism

Expiration policy:

  When we set key, you can give a expire time, time is expired

  After the expiration of this time, redis delete the use of key: + inert periodically delete delete

  Deleted regularly refers to the redis default within 100ms random sample of some of the key set expiration time, check for expired expired deleted.

  Periodically deletes random because many key is not deleted, delete it used inert

  When a query is inert to delete a key, under redis check this key has expired, expired deleted.

  

  But if you miss a lot of back regularly delete key, did not query can not delete inactive, resulting in the accumulation of a lot of back key memory, leading to memory exhaustion, then use the memory elimination mechanism.

 

Memory elimination mechanism:

  Generally used allkeys-lru: when the memory is insufficient to accommodate the new data is written, using the removal key in the key minimal space

  Recycling LRU algorithm:

    Use hash chain. Hash table consists of several key-value composition, these logical key, value is disordered. In the hash chain, each key-value has his predecessor key-value, the drive key-value, like a doubly linked list of nodes. In this way hash chain to order.

    The key-value hash list sorted by time.

    Every visit to the new key, which is inserted into the key-value list at the far right.

    When memory is low, the leftmost key-value deleted.

    

  

Guess you like

Origin www.cnblogs.com/zwp-627/p/11299415.html