使用StackExchange.Redis将数据集添加到Redis并检索数据集

8

我刚开始接触 Redis。我能够使用以下命令存储和检索数据到 Redis 中:

hmset user:user1 12 13 14 15 

并且我需要通过以下方式检索数据
hgetall user:user1

我希望在我的C#程序中使用StackExchange.Redis完成相同的操作。请问我应该如何实现?


你看过 https://github.com/StackExchange/StackExchange.Redis 上的文档吗? - thepirat000
是的,但我找不到适合我情况的确切方法。 - Praveen Mohan
这是我迄今为止尝试过的,HashEntry [] hashfield = new HashEntry [4] // 包含哈希条目,redisDB.HashSet(“user”,hashfield); - Praveen Mohan
1个回答

20

要在哈希表中设置多个值,您可以调用以下HashSet方法重载:

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("localhost");
IDatabase db = redis.GetDatabase();
db.HashSet("user:user1", new HashEntry[] { new HashEntry("12", "13"), new HashEntry("14", "15") });

8
我猜在stackoverflow.com上编写StackExchange.Redis文档是有道理的。 - Gerry

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接