ASP.Net redis存取方法

 [HttpGet]
        [Route("api/GetWuLianWang")]
        public List<WuLianWangInfo> WlWinfos(string name = "")
        {
            //定义变量list接受返回的集合
            var list = new List<WuLianWangInfo>();

            //定义redis
            RedisClient redis = new RedisClient("127.0.0.1");

            //将Redis赋值给list
            list = redis.Get<List<WuLianWangInfo>>("products");

            //判断Redis是否为空或者他的个数是否为0
            if (list == null || list.Count == 0)
            {
                list = dal.WlWInfos(name);

                redis.Set("products", list);
            }

            return list;

        }
View Code

原文地址:https://www.cnblogs.com/XJNB/p/13215807.html