예제 #1
0
        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());
        }