如何计算匹配模式的键数? [英] How to count the number of keys matching a pattern?

查看:78
本文介绍了如何计算匹配模式的键数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何找到所有具有匹配模式的键的数量.

How can I find the count of all the keys that has a matching pattern.

例如,有两个键 abc:random-text-1abc:random-text-2 .这里的常见模式是abc:.所以,这里的计数是 2.

For example, there are two keys abc:random-text-1 and abc:random-text-2 . The common pattern here isabc: . So, here the count is 2.

如何在 redis 中执行此操作?

How can I do this in redis?

推荐答案

免责声明 我希望这个旧答案没有损坏任何具有数百万个密钥的生产系统.如果出于某种原因仍然想统计redis在生产中的匹配key,最好使用scan带有匹配模式.

DISCLAIMER I hope this old answer haven't damaged any production systems, with millions of keys. If you still want to still count the matching keys of redis in production for some reason, better use scan with a match pattern.

如果您只是使用 KEYS 进行搜索,使用您的 redis 客户端,您将获得所有匹配键的数字列表,对吗?

If you simply search with KEYS, with your redis client, you will get a number list of all you matching keys, right?

例如

KEYS abc:*

会给你

1) abc:random-text-1
2) abc:random-text-2

或者您可以运行以下命令:

or you can run the following:

./redis-cli KEYS "abc:*" | wc -l

你会得到 2 作为输出.

and you will get 2 as an output.

这篇关于如何计算匹配模式的键数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆