Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The solution of full memory in redis

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the solution that redis memory is full, which is very detailed and has certain reference value. Friends who are interested must finish it!

Redis memory is full of solutions:

1. Increase the memory.

2. Use the memory elimination strategy.

3Grammer Redis cluster.

Focus on the following 2 and 3:

The second point:

We know that redis sets the maxmemory parameter of the configuration file to control its maximum available memory size (bytes).

So what happens when the required memory exceeds maxmemory?

At this point, it's time for maxmemory-policy in the configuration file to come out.

Its default value is noeviction.

Below I will list the elimination rules for deleting the redis key when there is insufficient available memory.

Rule description:

1 、 volatile-lru

Delete a key using the LRU algorithm (only for keys with time to live)

2 、 allkeys-lru

Delete a key using the LRU algorithm

3 、 volatile-random

Randomly delete a key (only for keys with time to live)

4 、 allkeys-random

Randomly delete a key

5 、 volatile-ttl

Delete the most recent key in time to live

6 、 noeviction

Do not delete the key, only return an error

LRU algorithm, least RecentlyUsed, the least recently used algorithm. That is, the least recently used keys are deleted by default.

But you have to be careful! Redis does not accurately delete the least used keys of all keys, but selects 3 keys at random to delete the least used keys of the three keys.

Then the number 3 can also be set, corresponding to the maxmeory-samples in the configuration file.

Third, how to do the cluster

Redis only supports a single instance, and generally has a maximum memory of 10~20GB. For systems with 100~200GB memory, they need to be supported by clusters.

There are three ways to cluster Redis: client sharding, proxy sharding, and RedisCluster (more on that in a later article).

1. Client sharding

Implement routing by yourself through business code

Advantages: you can control the slicing algorithm by yourself, and the performance is better than that of the agent.

Disadvantages: high maintenance costs, expansion / reduction and other operation and maintenance operations need their own research and development.

2. Agent slicing

The agent receives data requests from the business program and, according to routing rules, distributes these requests to the correct Redis instance and returns them to the business program. It is implemented using middleware such as Twemproxy, Codis and so on.

Advantages: convenient operation and maintenance, programs do not have to care about how to link Redis instances

Disadvantages: it causes performance consumption (about 20%), cannot smoothly expand / reduce capacity, and needs to execute scripts to migrate data, which is inconvenient (Codis optimizes and implements pre-sharding to achieve Auto Rebalance based on Twemproxy).

3 、 Redis Cluster

Advantages: official cluster solution, no central node, directly connected to the client, good performance

Disadvantages: the solution is too heavy to smooth capacity expansion / reduction, and the corresponding script needs to be executed, which is inconvenient, too new, and there is no corresponding mature solution.

The above are all the solutions of redis with full memory. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report