.net - redis 获取列表,其中有键开头

标签 .net redis

我为 Redis 设置了一些键,键格式为 "userId-barcodeNo"

例如:

Key : 1-54a5f4, Value : {"Name":"Erkan"}

现在我需要获取一个列表,其中的键以“userId”开头。

我可以通过包含字符 (*) - http://redis.io/commands/KEYS 来获取 key 列表

KEYS *UserId*

但是我怎样才能获得带有以 userId 开头的键的项目

我需要这样的东西:Get *UserId*

在 .Net 中这是我的代码

        using (var ioc = new Ioc())
        {
            var client = ioc.Resolve<IRedisClientsManager>().GetClient();
            var key = string.Format("*{0}*", User.Identity.GetUserId());
            var list = client.Get<Coupon>(key);
        }

它返回空值。

redis 支持吗?

最佳答案

您可以使用 MGET 一次获取所有 key 。因此,您可以在一个调用中获取键,而不是在另一个调用中捕获值。 http://redis.io/commands/mget

关于.net - redis 获取列表,其中有键开头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28105147/

相关文章:

.net - 如何取消选择 DataGridView 控件中的所有选定行?

c# - MS Dynamics CRM 插件错误 - [A]CrmWebSvc 无法转换为 [B]CrmWebSvc

c# - 在 .NET Core 2.1 中使用通用主机正常关闭

memory - Redis 中 maxmemory_policy 的可能值是多少?

Symfony2 通过集成测试的 API 对用户进行身份验证

python - rq (redis queue) work-horse 意外终止,关于如何调试的建议?

node.js - 如何让socket.io在pm2集群模式下正常工作?

c# - 大写排列

performance - 如何识别 Redis 性能/瓶颈

.net - MSBuild 错误 : "Could not resolve this reference. Could not locate the assembly..."