C#对redis中同类型数据分类

往redis里面写日K线,和分K线的时候,觉得应该可以把这两种类型都存在一个数据库(db)中,并对两者进行区分。

查了一些资料,终于找到了,感觉还是挺实用的,做下记录,以免忘记。

以下代码为demo,其中client为RedisClient对象:

                string stringKey = "demo1";
                Dictionary<string, string> orderList = new Dictionary<string, string>();
                orderList.Add("openwndtime", "130831810820000000");
                orderList.Add("opensystime", "130831810820000000");
                orderList.Add("dur", "222222");
                orderList.Add("open", "222222");
                orderList.Add("close", "222222");
                orderList.Add("high", "222222");
                orderList.Add("low", "222222");
                string time = string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now);
                foreach (var order in orderList)
                {
                    
                    client.HSet(stringKey + ":" + time, Encoding.UTF8.GetBytes(order.Key), Encoding.UTF8.GetBytes(order.Value)); //创建个key-field
                } 

上述代码中数据,在redisManage中查看为:



仿佛跟建了个文件夹一样。

猜你喜欢

转载自blog.csdn.net/u012605477/article/details/79397763