/// <summary> /// 获取全部列表(Redis缓存) /// </summary> /// <returns></returns> public static List <Product_Class> GetListCache() { try { string key = "ProClass"; if (RedisProvider.KeyExistSync(key)) { string str = RedisProvider.StringGetSync(key); return(Tools.Tool.JsonHelper.Deserialize <Product_Class>(str)); } else { var list = GetList(); if (list != null && list.Count > 0) { //缓存过期时间-1天更新一次 TimeSpan ts = new TimeSpan(DateTime.Now.AddDays(1).Ticks - DateTime.Now.Ticks); RedisProvider.StringSetSync(key, Tools.Tool.JsonHelper.Serialize(list), ts); } return(list); } } catch (Exception ex) { Tools.Tool.LogHelper.WriteLog(typeof(BllProduct_Class), ex, Tools.Utility.User.GetMyMemberId(), Tools.Utility.User.GetMyMemberName()); return(null); } }
public async Task <IActionResult> Index() { ViewBag.Company = "Welfull"; ViewBag.Name = "Harry"; //创建数组 string[] names = new string[] { "ZeosonY", "XuZ", "Owen", "Actor", "Director" }; ViewBag.Names = names; //创建字典 Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("ZeosonY", "想做鱼"); dic.Add("XuZ", "Lave"); dic.Add("Owen", "Owen"); dic.Add("Actor", "演员"); dic.Add("Director", "导演"); //插入到redis-string RedisProvider.StringSetSync(dic); //插入到redis-list foreach (var item in dic) { //左侧插入 await RedisProvider.ListLPush("MyList", item.Value); //从右侧删除并获取 await RedisProvider.ListRightPop("MyList"); } //string对集合 NameValueCollection list = new NameValueCollection(); list.Add("XuZ", "username1"); list.Add("XuZ", "username2"); list.Add("LiuD", "username3"); //设置cookie Tools.Utility.CookieHelper.SetObj("XXX", 120, list); Tools.Utility.CookieHelper.SetObj("YZX", 120, "XZY"); ViewBag.Dic = dic; return(View()); }