Esempio n. 1
0
        public string AddCar(int goodId, int goodNum)
        {
            ProductInfo info = _goodsList.GetProductinfo(goodId);

            if (info.ProductAmount < goodNum)
            {
                return("库存不足");
            }
            info.ProductAmount = goodNum;

            List <ProductInfo> list = redis.Get <List <ProductInfo> >("shopcar");

            //商品购物车是不是空的
            if (list != null)
            {
                var m = list.Where(x => x.ProductId == goodId).FirstOrDefault();
                if (m != null)
                {
                    return("已加入该商品");
                }
                else
                {
                    list.Add(info);
                    //return "加入成功";
                }
            }
            else
            {
                list = new List <ProductInfo>();
                list.Add(info);
            }
            redis.Set("shopcar", list);
            redis.Expire("shopcar", 3600);
            return("加入成功");
        }
Esempio n. 2
0
        private void Refresh(string key, DateTimeOffset?absExpr, TimeSpan?sldExpr)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            // Note Refresh has no effect if there is just an absolute expiration (or neither).
            TimeSpan?expr = null;

            if (sldExpr.HasValue)
            {
                if (absExpr.HasValue)
                {
                    var relExpr = absExpr.Value - DateTimeOffset.Now;
                    expr = relExpr <= sldExpr.Value ? relExpr : sldExpr;
                }
                else
                {
                    expr = sldExpr;
                }
                _redisClient.Expire(key, expr ?? TimeSpan.Zero);
                // TODO: Error handling
            }
        }