In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Redis cleans up the key of a prefix
For example, a research and development of online code, resulting in a certain prefix key dirty data (for example, the key prefix name is key_), we need to quickly clean up these problems key.
There are two common methods:
1. Dump produces a full amount of data, then finds out the key that meets the conditions, and deletes it [recommended]
2. Scan the redis with scan, fish out all the key, and then delete the qualified key
We use the first method here, as follows:
1. On the slave node, bgsave commands dump to output a full amount of data
Bgsave, the generated file name is similar to dump-6379.rdb
2. Install the rdb parsing tool
The next line of command pip install rdbtools python-lzf # python2.7 can complete the installation of rdb-c memory dump-6379.rdb > memory.csv # use this command to analyze rdb
3. Filter out the qualified key
Awk-F',''{print $3 $NF} 'memory.csv > keys.txt # filter out the name and expiration time of the key egrep key_ keys.txt > / root/key_.txt # filter out the key of the key_ prefix cat / root/key_.txt | sort-k 2-r > / root/sort_keys # sort the key in reverse order by date egrep 2019-09-10 / root/sort_keys > / root/match_keys # Note: I am here to deal with urgently Only 2019-09-10 expired key is filtered (this is the latest data and the most frequently visited key in business at present. Awk'{print $1}'/ root/match_keys > / root/filter_keys # redirects the final key to a file mkdir / root/test/split-2000 / root/filter_keys / root/test/ # splits the filter_keys into multiple files according to each 2k line for subsequent parallel processing
Then, let's write a script and batch process:
The vim / root/batch.sh content is as follows:
For i in `ls / root/test/ `; doecho "while read line;doecho\" del\ $line\ "| redis-cli-h 127.0.0.1-p 6379 done
< /root/test/${i}" >/ root/run_$ {I} .shchmod + x / root/run_$ {I} .sh done
This generates a bunch of scripts.
Let's write a script and execute it in batch.
#! / bin/bashfor I in `ls run* .sh`; do nohup sh $I > / dev/null & done
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.