Exemple #1
0
        public static void Show()
        {
            Student student_1 = new Student()
            {
                Id   = 11,
                Name = "Eleven"
            };
            Student student_2 = new Student()
            {
                Id     = 12,
                Name   = "Twelve",
                Remark = "123423245"
            };

            Console.WriteLine("====Basic redis test====");
            {
                using (RedisStringService service = new RedisStringService())
                {
                    service.Set <string>("student1", "May");
                    Console.WriteLine(service.Get("student1"));

                    service.Append("student1", " from china");
                    Console.WriteLine($"After append : {service.Get("student1")}");

                    service.GetAndSetValue("student1", "Modified May ");
                    Console.WriteLine(service.Get("student1"));

                    service.Set <string>("stu2", "Lee", DateTime.Now.AddSeconds(5));
                    //Thread.Sleep(1000);
                    Console.WriteLine(service.Get("stu2"));

                    service.Set <int>("age", 23);
                    service.Incr("age");
                    Console.WriteLine($"After Incr: {service.Get("age")}");
                    service.IncrBy("age", 10);
                    Console.WriteLine($"After Incr by 10: {service.Get("age")}");
                    service.Decr("age");
                    Console.WriteLine($"After Decr: {service.Get("age")}");
                    service.DecrBy("age", 10);
                    Console.WriteLine($"After Decr by 10: {service.Get("age")}");
                }

                {
                    Console.WriteLine("===Basic redis hash table===");
                    using (RedisHashService service = new RedisHashService())
                    {
                        service.SetEntryInHash("stuHash", "id", "123");
                        service.SetEntryInHash("stuHash", "name", "MayHash");
                        service.SetEntryInHash("stuHash", "remark", "Graudate");

                        var keys      = service.GetHashKeys("stuHash");
                        var values    = service.GetHashValues("stuHash");
                        var keyValues = service.GetAllEntriesFromHash("stuHash");

                        string valueId = service.GetValueFromHash("stuHash", "id");
                        Console.WriteLine(valueId);

                        service.SetEntryInHashIfNotExists("stuHash", "name", "MayHashUpdated");
                        service.SetEntryInHashIfNotExists("stuHash", "description", "Advanced class");
                        Console.WriteLine(service.GetValueFromHash("stuHash", "name"));
                        Console.WriteLine(service.GetValueFromHash("stuHash", "description"));
                        service.RemoveEntryFromHash("stuHash", "description");
                        Console.WriteLine($"After remove: {service.GetValueFromHash("stuHash", "description")}");
                    }
                }
            }
        }
        public ActionResult AjaxCreate([Bind(Include = "Id, residential, building, unit, deviceid, chinaname, devtype")] hsf_outdevice hsf_outdevice)
        {
            if (!string.IsNullOrEmpty(hsf_outdevice.deviceid))
            {
                hsf_outdevice.Id         = Guid.NewGuid().ToString();
                hsf_outdevice.createtime = DateTime.Now;
                hsf_outdevice.deletemark = 0;
                hsf_outdevice newhsf_outdevice = ihsf_outdeviceService.Insert(hsf_outdevice);

                using (RedisHashService service = new RedisHashService())
                {
                    //室外,大华产品
                    string _residential = hsf_outdevice.residential;                    //小区
                    string _building    = hsf_outdevice.building;                       //楼号
                    string _unit        = hsf_outdevice.unit;                           //单元
                    string cachekey     = _residential + "-" + _building + "-" + _unit; //默认房间

                    //清除当前设备类型的设备列表缓存
                    if (string.IsNullOrEmpty(_building) && string.IsNullOrEmpty(_unit))
                    {
                        //MMSJ--,整个所在小区添加公共设备,比如公共摄像头,所有业主的缓存全部删除
                        List <string> ods = service.GetHashKeys("OutDevices");
                        foreach (var item in ods)
                        {
                            if (item.Contains(_residential))
                            {
                                service.RemoveEntryFromHash("OutDevices", item);
                            }
                        }
                    }
                    else if (string.IsNullOrEmpty(_unit))
                    {
                        //MMSJ-1-所在楼号添加公共设备,比如楼号摄像头,楼号内业主的缓存全部删除
                        List <string> ods = service.GetHashKeys("OutDevices");
                        foreach (var item in ods)
                        {
                            if (item.Contains(_residential + "-" + _building))
                            {
                                service.RemoveEntryFromHash("OutDevices", item);
                            }
                        }
                    }
                    else
                    {
                        //MMSJ-1-1所在单元设备变动,比如单元门,单元内业主的缓存全部删除
                        service.RemoveEntryFromHash("OutDevices", cachekey);
                    }

                    logger.Debug($"清除当前单元的室外设备列表 {cachekey}");
                }

                AjaxResult ajaxResult = new AjaxResult()
                {
                    Result    = DoResult.Success,
                    PromptMsg = "插入成功"
                };
                return(Json(ajaxResult));
            }
            else
            {
                logger.Debug($"error:id不能为空!");
                AjaxResult ajaxResult = new AjaxResult()
                {
                    Result    = DoResult.Failed,
                    PromptMsg = "id不能为空"
                };
                return(Json(ajaxResult));
            }
        }