故如虹,知恩;故如月,知明
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术

ServiceStack.Redis操作Redis之Hash

7291人阅读 2019/6/3 16:37 总访问:3911629 评论:0 收藏:0 手机
分类: Redis


下面是使用ServiceStack.Redis库对redis中的Hash简单的,增删改查操作

 using (RedisClient client = new RedisClient("127.0.0.1", 6379))
            {

                //添加/修改
                client.SetEntryInHash("userhash", "u1", "李白");
                client.SetEntryInHash("userhash", "u2", "韩信");
                client.SetEntryInHash("userhash", "u3", "赵云");

                //获取
                string value = client.GetValueFromHash("userhash", "u2");
                Console.WriteLine(value);

                //删除
                client.RemoveEntryFromHash("userhash", "u2");

                //遍历键值对
                Dictionary<string, string> kvalue = client.GetAllEntriesFromHash("userhash");
                foreach (var item in kvalue)
                {
                    Console.WriteLine(item.Key + ":" + item.Value);
                }

                //输出所有的key
                List<string> keys = client.GetHashKeys("userhash");
                foreach (string item in keys)
                {
                    Console.WriteLine(item);
                }

                //输出所有的value
                List<string> values = client.GetHashValues("userhash");
                foreach (string item in values)
                {
                    Console.WriteLine(item);
                }

                //清空
                foreach (string key in keys)
                {
                    client.RemoveEntryFromHash("userhash", key);
                }
            }


欢迎加群讨论技术,群:677373950(满了,可以加,但通过不了),2群:656732739

评价