Home >Database >Redis >How to ensure that all hot data in redis is

How to ensure that all hot data in redis is

(*-*)浩
(*-*)浩Original
2019-11-28 09:45:373579browse

How to ensure that all hot data in redis is

When the memory used by redis exceeds the set maximum memory, the key elimination mechanism of redis will be triggered. There are 6 elimination strategies in redis 3.0:

noeviction: Do not delete the policy. When the maximum memory limit is reached, if more memory needs to be used, an error message is returned directly. (Redis default elimination strategy)

allkeys-lru: Prioritize deleting the least recently used (LRU) key among all keys. (Recommended learning: Redis Video Tutorial)

allkeys-random: Randomly delete some keys among all keys.

volatile-lru: Prioritize deleting the least recently used (LRU) key among the keys with a timeout (expire) set.

volatile-random: Randomly delete some keys among the keys with a timeout (expire) set.

volatile-ttl: Prioritize deleting keys with a short remaining time (time to live, TTL) among keys with a timeout (expire) set.

Scenario:

There are 10 million data in the database, but only 500 thousand data in redis. How to ensure that the 100 thousand data in redis are hot data?

Plan:

Limit the memory occupied by Redis. Redis will leave hot data in the memory according to its own data elimination strategy. So, calculate the approximate memory occupied by 50W data, then set the Redis memory limit, and set the elimination strategy to volatile-lru or allkeys-lru.

Set the maximum memory occupied by Redis:

Open the redis configuration file and set the maxmemory parameter. maxmemory is the bytes byte type

# In short... if you have slaves attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
# maxmemory <bytes>
maxmemory 268435456

Settings Expiration policy:

maxmemory-policy volatile-lru

For more Redis-related technical articles, please visit the Redis Getting Started Tutorial column to learn!

The above is the detailed content of How to ensure that all hot data in redis is. 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