Home  >  Article  >  Database  >  What are the redis memory elimination mechanisms?

What are the redis memory elimination mechanisms?

hzc
hzcOriginal
2020-06-28 14:44:126802browse

The redis memory elimination mechanism includes: 1. noeviction, when the memory usage reaches the threshold, all commands that cause memory application will report an error; 2. allkeys-lru, in the primary key space, remove the recently unused ones first key; 3. allkeys-random, in the primary key space, randomly removed.

What are the redis memory elimination mechanisms?

Memory elimination strategy

Memory elimination is just a function provided by Redis. In order to better realize this function, it must be used for different application scenarios. Different strategies are provided. The memory elimination strategy talks about what we do specifically to achieve memory elimination. The problems to be solved include how to choose the elimination key space? How to choose the key to eliminate in the key space?

Redis provides the following elimination strategies for users to choose from, the default strategy is noeviction Strategy:

  • noeviction: When the memory usage reaches When the threshold is reached, all commands that cause memory application will report an error

  • allkeys-lru: In the primary key space, remove the recently unused ones first

  • keyvolatile-lru: In the key space with an expiration time set, remove the recently unused ones first

  • keyallkeys-random: In the primary key space, randomly remove a

  • keyvolatile-random: Randomly remove a key in the key space with expiration time set.

  • keyvolatile-ttl: In the key space with expiration set, In the key space of time, keys with earlier expiration times are removed first.

Here we add the primary key space and the key space with expiration time set. For example, suppose we have a batch of If the keys are stored in Redis, there is a hash table used to store the keys and their values. If some of the keys have an expiration time, the keys will be stored in another hash table. , the value in this hash table corresponds to the expiration time when the key is set. The key space with expiration time set is a subset of the primary key space.

Recommended tutorial: "Redis Tutorial"

The above is the detailed content of What are the redis memory elimination mechanisms?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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