我为 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/