简体   繁体   English

如何获取StackExchange.Redis的密钥数?

[英]How can I get a key count for StackExchange.Redis?

I have an azure redis cache. 我有一个天蓝色的redis缓存。 I've set it up so that I can do stringGet key setting based off this example. 我已经设置好了,所以我可以根据这个例子做stringGet键设置。 It works pretty great. 它非常棒。

However, I want to know if the cache is empty or not, or if there are any entries of (x) type of a C# object I have. 但是,我想知道缓存是否为空,或者是否有(x)类型的C#对象的条目。 I currently want to see if I can get a key count. 我目前想知道我是否可以得到钥匙数。 I haven't found any solutions for this. 我还没有找到任何解决方案。

My only idea is to do a key scan that would search for every key (a get all) and then do a count. 我唯一的想法是进行一次密钥扫描,搜索每一个密钥(全部获取),然后进行计数。 But that seems inefficient. 但这似乎效率低下。 Is there a more "meta" data style solution? 是否有更“元”的数据风格解决方案?

Thanks! 谢谢!

Per my understanding, you could leverage IServer.Keys to retrieve all keys with matching pattern as follows: 根据我的理解,您可以利用IServer.Keys检索具有匹配模式的所有键,如下所示:

var endpoints=ConnectionMultiplexer.GetEndPoints();
var server = ConnectionMultiplexer.GetServer(endpoints.First());
var keys = server.Keys();

For more details about keys scanning, you could refer to this tutorial . 有关键扫描的更多详细信息,请参阅本教程

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

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