如何获取redis中的键数? [英] How can I get the count of keys in redis?

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

问题描述

我可以用这个命令获取一些密钥:

I can get some keys with this command:

keys *_products_*

但是该命令返回所有键,我只需要这些键的计数.我怎样才能得到它?

However that command returns all the keys, where I just need the count of those. How can I get It?

推荐答案

您可以使用 DBSIZEINFO KEYSPACE

You can use DBSIZE or INFO KEYSPACE

但是如果您想要名称中具有特定模式的所有键,则需要使用 KEYSSCAN 并且需要注意KEYS,在生产中运行会影响性能,因此应谨慎使用.

But if you want all the keys with a certain pattern in the name you need to use KEYS or SCAN And you need to pay attention to KEYS, running it in production can affect the performance so it should be used with caution.

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

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