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

What if redis memory exceeds maxmemory?

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

Share

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

Redis memory is full of solutions:

1. Increase memory

2. Use the memory elimination strategy.

3Grammer Redis cluster.

Let's focus on the second and third solutions:

The second kind:

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.

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.

The third method:

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 of Redis cluster: client sharding, proxy sharding, and RedisCluster

Client slicing

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.

Proxy 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).

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.

These are the details of the solution that redis memory is full of. Please pay more attention to other related articles!

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