简体   繁体   English

如何在 Azure Redis 缓存控制台中查看匹配模式的键计数

[英]How to see key count of matching pattern in Azure Redis Cache Console

I want to just see the total number of keys available in Azure Redis cache that matches the given pattern.我只想查看与给定模式匹配的 Azure Redis 缓存中可用的密钥总数。 I tried the following command it is showing the count after displaying all the keys (which caused server load), But I need only the count.我尝试了以下命令,它在显示所有键(导致服务器负载)后显示计数,但我只需要计数。

>SCAN 0 COUNT 10000000 MATCH "{UID}*"

Except command SCAN , the command KEYS pattern can return the same result as your current command SCAN 0 COUNT 10000000 MATCH "{UID}*" .除了命令SCAN ,命令KEYS pattern可以返回与当前命令SCAN 0 COUNT 10000000 MATCH "{UID}*"相同的结果。

However, for your real needs to get the number of keys matching a pattern, there is an issue add COUNT command from the Redis offical GitHub repo which had answered by the author antirez for you, as the content below.但是,对于您真正需要获取与模式匹配的键的数量,Redis 官方 GitHub 存储库中有一个问题add COUNT command ,该存储库已由作者antirez为您回答,内容如下。

Hi, KEYS is only intended for debugging since it is O(N) and performs a full keyspace scan.嗨,KEYS 仅用于调试,因为它是 O(N) 并执行完整的键空间扫描。 COUNT has the same problem but without the excuse of being useful for debugging... (since you can simply use redis-cli keys... | grep...). COUNT 有同样的问题,但没有对调试有用的借口......(因为你可以简单地使用 redis-cli 键......| grep......)。 So feature not accepted.所以功能不被接受。 Thanks for your interest.感谢您的关注。

So you can not directly get the count of KEYS pattern , but there are some possible solutions for you.所以你不能直接得到KEYS pattern的数量,但有一些可能的解决方案。

  1. Count the keys return from command KEYS pattern in your programming language for the small number of keys with a pattern, like doing redis-cli KEYS "{UID}*" | wc -l在您的编程语言中计算从命令KEYS pattern返回的键,以获取少量具有模式的键,例如redis-cli KEYS "{UID}*" | wc -l redis-cli KEYS "{UID}*" | wc -l on the host server of Redis.在 Redis 的主机服务器上redis-cli KEYS "{UID}*" | wc -l

  2. To use the command EVAL script numkeys key \[key...\] arg \[arg...\] to run a Lua script to count the keys with pattern, there are two scripts you can try.要使用命令EVAL script numkeys key \[key...\] arg \[arg...\]运行 Lua 脚本来计算带有模式的键,您可以尝试两个脚本。

    2.1. 2.1。 Script 1脚本 1

     return #redis.call("keys", "{UID}*")

    2.2. 2.2. Script 2脚本 2

     return table.getn(redis.call('keys', ARGV[1]))

    The completed command in redis-cli is EVAL "return table.getn(redis.call('keys', ARGV[1]))" 0 {UID}* redis-cli中完成的命令是EVAL "return table.getn(redis.call('keys', ARGV[1]))" 0 {UID}*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM