简体   繁体   English

如何在 C# 代码的 Redis 缓存中使用 HSET 命令?

[英]How to use the HSET command in Redis cache from C# code?

I am kind of new to Redis Cache.我对 Redis 缓存有点陌生。 I have implemented calling the Redis server from my C# code by using this article link .我已经使用本文链接从我的 C# 代码中调用 Redis 服务器。 I could able to set the values in Redis DB using the SetValue() method.我可以使用 SetValue() 方法在 Redis DB 中设置值。 But I am not sure on how to set Hash values in Redis cache from C# code and I couldn't able to get a good example on the internet.但我不确定如何从 C# 代码在 Redis 缓存中设置 Hash 值,我无法在互联网上找到一个很好的例子。 Please help me with this.请帮我解决一下这个。

Thank you in Advance先感谢您

Docs are definitely vague on this.文档对此肯定含糊不清。 After skimming the repo, SetEntryInHash appears to be what you want.浏览 repo 后, SetEntryInHash似乎是您想要的。

        public bool SetEntryInHash(string hashId, string key, string value)
        {
            return base.HSet(hashId, key.ToUtf8Bytes(), value.ToUtf8Bytes()) == Success;
        }

https://github.com/ServiceStack/ServiceStack.Redis/blob/master/src/ServiceStack.Redis/RedisClient_Hash.cs#L51-L54 https://github.com/ServiceStack/ServiceStack.Redis/blob/master/src/ServiceStack.Redis/RedisClient_Hash.cs#L51-L54

You can add a new entry to the hash using method SetEntryInHash(string hashId, string key, string value) or add a list of entries using method SetRangeInHash(string hashId, IEnumerable<KeyValuePair<string, string>> keyValuePairs)您可以使用方法SetEntryInHash(string hashId, string key, string value)将新条目添加到 hash 或使用方法SetRangeInHash(string hashId, IEnumerable<KeyValuePair<string, string>> keyValuePairs)添加条目列表

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

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