In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to understand Redis's keys command". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to understand the keys command of Redis.
Usage of the keys command:
Keys pattern
Find a list of key that match the regular match. The scanning object is all the key in the Redis service. Is it right to think that they are all very slow?
When executing the keys command at the same time, the Redis process will be blocked and unable to execute other commands. If the down-after-milliseconds configuration of the Sentinel is exceeded, the master-slave handover will be carried out. During the handover process, a series of problems such as brain fissure may occur if the master node returns to normal.
Therefore, in a production environment, it is recommended to disable the keys command directly.
Alternatives to the Keys command
1. Scan scan to avoid blocking
2. Put the data to be counted into a set (but this may lead to Big Key problems, which is not recommended if there is a large amount of data)
How is the Keys command executed in Redis Cluster?
Generally speaking, the keys command does not know which node the path is going to for the cluster node, unlike the get command. In the JedisClusterKeyCommands class of the Jedis client of Java, we see:
Public Set keys (byte [] pattern) {/ execute the keys command Collection keysPerNode = connection.getClusterCommandExecutor () .executeCommandOnAllNodes ((JedisClusterCommandCallback) client-> client.keys (pattern)) .resultsAsList () on each node / / when merged into a whole, Set keys = new HashSet (); for (Set keySet: keysPerNode) {keys.addAll (keySet);} return keys;} is returned
We see that Jedis is returned by executing the keys command on each node and merging the results.
Since the keys command is slow in this article, how slow is it?
How slow is the Keys command?
The main purpose here is to give you a basic concept, not an in-depth analysis.
This is the log of slow query in Redis cluster service on Tencent Cloud. We can see that the Keys command probably executes 250ms ~ 300ms.
According to the node information, we can see that each node stores about 153w of key, occupying 300Mbps of memory, and each key-value pair occupies memory 0.208KB of 213 bytes on average.
As far as I understand it, since the keys command returns a key value, there is actually a structure in the cluster, slots_to_keys, that records all key, which is only related to the number of key, not Big key.
According to this guess, if the Redis node occupies 3G memory and the number of Key is proportional, then the execution time of the Keys command is about 3 seconds, during which time the Redis node is blocked.
At this point, I believe you have a deeper understanding of "how to understand Redis's keys command". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.