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 view Redis Key resource usage

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Editor to share with you how to check the use of Redis Key resources, I hope you have something to gain after reading this article, let's discuss it together!

In daily development, Redis accumulates a lot of Key and takes up a lot of memory space. Sometimes we want to know how many Key there are in the current Redis and which Key takes up the most memory.

However, we know that because Redis is a single-threaded database, the online environment absolutely forbids the use of the keys * command, because it takes a long time to scan all Key, and in the process, the Redis will get stuck and cannot handle other read and write operations.

So, how do we know how many Key are currently available? Some students said that you can use the scan command. But on the one hand, this command needs to write a program to iterate, on the other hand, the results it gives may be inaccurate.

Some students will also say that you can use the info keyspace command, and the running effect is as follows:

You can really see how many Key there are. But the other question is, how do you know which Key takes up the most memory space?

Sometimes, there may be tens of thousands of Key in Redis, some of which can be deleted. But since we can't use the keys command to see which Key are currently available, we don't know that the Key that can be deleted is still there.

In fact, these problems can be solved by using a tool called RDR [1]. On RDR's Github, you can find the executable file for the corresponding system. Let's take the Linux version as an example. The executable file address of the Linux version is: https://github.com/xueqiu/rdr/releases/download/v0.0.1/rdr-linux. After downloading, grant the executable permission:

Cd ~ wget https://github.com/xueqiu/rdr/releases/download/v0.0.1/rdr-linux chmod + x rdr-linux

Next, we need to find the dump.rdb file.

Redis enables persistent storage in RDB mode by default. When certain conditions are met, Redis will store the data in memory on the hard disk to prevent data loss due to a sudden power outage. By default, the RDB file is in / var/lib/redis/dump.rdb, which can only be read by root users.

If you are not a root user, you can copy it out and modify it to the current user. The current user of my Linux system is called kingname, and the user group is also called kingname, so you can execute the following shell command:

Cd ~ sudo cp / var/lib/redis/dump.rdb. / sudo chown kingname:kinganme dump.rdb

After modifying the user, we now have RDR read the RDB file:

. / rdr-linux show-p 8766 dump.rdb

The running effect is shown in the following figure:

Now, open the browser and http://IP:8766, and you can see the statistics of each Key of the current Redis:

After reading this article, I believe you have a certain understanding of "how to check Redis Key resource usage". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

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

Internet Technology

Wechat

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

12
Report