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("加入成功"); }
public void Test1() { var csredis = new CSRedis.CSRedisClient("localhost:6379,defaultDatabase=13,poolsize=10"); var pong = csredis.Ping(); Assert.True(pong); var flag = csredis.Set("key", "123"); Assert.True(flag); var val = csredis.Get("key"); Assert.Equal("123", val); }
private string getRedisData(IConfigurationSection section, string rediskey) { var redisconn = GetService <DBInfo>(section.Value); CSRedis.CSRedisClient csredis; try { csredis = new CSRedis.CSRedisClient(ConnSecure.Decrypt(redisconn.RedisConnStr)); RedisHelper.Initialization(csredis); } catch (Exception err) { NCLog.ExceptionLog(err, $"getRedisData error: {err.Message}"); throw new Exception($"getRedisData error: {err.Message}"); } var tokenstr = csredis.Get(rediskey); return(tokenstr); }
public void RedisSampleTest() { var defaultValue = _redis.Get("samplekey"); Assert.True(string.IsNullOrWhiteSpace(defaultValue)); }