Introduction to the LRU mechanism of Redis _redis

Source: Internet
Author: User
Tags allkeys redis volatile redis server

In Redis, if set maxmemory, it is necessary to configure the key recovery mechanism parameters Maxmemory-policy, default VOLATILE-LRU, see Redis author's original blog: Antirez weblog >> Redis As an LRU cache

It is clearly written in the original text:

Copy Code code as follows:

Another way to use Redis as a cache are the MaxMemory directive, a feature that allows specifying a maximum amount of memor Y to use. When the new data are added to the server, and the memory limit was already reached, the server would remove some old data delet ing a volatile key, which, a key with a EXPIRE (a timeout) set, even if the key is still far from expiring Automaticall Y.

When the Redis server takes up memory to MaxMemory, when you want to increase the memory footprint, the old data will be deleted by the maxmemory-policy mechanism. Here's a brief volatile-lru,redis will press the LRU algorithm to delete the set expiration time but has not expired key, and for the Key,redis that have not set expiration time is reserved forever. Of course, if you don't want to delete a key that doesn't expire, you can use the noeviction mechanism
Copy Code code as follows:

# maxmemory Policy:how Redis'll select what to remove when maxmemory
# is reached? You can select among five behavior:
#
# VOLATILE-LRU-> Remove the key with a expire set using an LRU algorithm
# ALLKEYS-LRU-> Remove any key accordingly to the LRU algorithm
# volatile-random-> Remove a random key with a expire set
# allkeys-random-> Remove a random key, any key
# Volatile-ttl-> Remove the key with the nearest Expire time (minor TTL)
# noeviction-> don ' t expire at all, just return a error on write operations

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.