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

How to delete data according to mode in Redis

2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Xiaobian to share with you how to delete data in Redis according to the mode, I believe most people still do not know how to, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!

A Redis server consumes dozens of gigabytes of memory in a very short period of time and eventually goes down due to SWAP. Because the social background of this server is relatively complex, it is impossible to determine who the suspect is at the moment.

The initial intuition was that someone must have saved a large amount of data, so the problem became to find out which keys took up more space, and DBA colleagues used tools such as redis-rdb-tools to analyze the data file. Unfortunately, although some large keys were found, they were eventually ruled out as suspects, and the problem seemed to have reached an impasse.

After our intuition led us to a dead end, we began to adjust the angle of our investigation: even if a key itself does not take up a lot of space, if the number of keys in the same pattern is large, it will take up a lot of space together, so the problem becomes to find out which keys in the same pattern take up a lot of space. This time I don't want to use any tools, but I plan to delete suspicious keys on the test server and check the memory changes:

shell> /path/to/redis-cli keys foo:* | xargs /path/to/redis-cli del

Tragically, the server hangs up as soon as you run this command! Because there was too much data, KEYS couldn't stand it. SCAN should be used in this case, which has the concept of cursors and involves very little data per iteration.

Using SCAN directly from the command line was a bit troublesome, so I used PHP:

While deleting, pay attention to monitoring memory changes, you can confirm the problem:

shell> watch -d -n 1 '/path/to/redis-cli info | grep memory'

As for the acquisition of suspicious keys, I am blind, simply through MONITOR or SCAN to obtain sample data, and from this case, the change in the total number of monitoring keys is very important, from INFO can get it.

The above is all the content of this article "How to delete data by mode in Redis". Thank you for reading it! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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

Servers

Wechat

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

12
Report