We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
秒杀下单时的一段代码: //预减库存 long stock = redisService.decr(GoodsKey.getGoodsStock, "" + goodsId);//10 if (stock < 0) { afterPropertiesSet(); long stock2 = redisService.decr(GoodsKey.getGoodsStock, "" + goodsId);//10 if(stock2 < 0){ localOverMap.put(goodsId, true); return Result.error(CodeMsg.SECKILL_OVER); } }
//预减库存 long stock = redisService.decr(GoodsKey.getGoodsStock, "" + goodsId);//10 if (stock < 0) { afterPropertiesSet(); long stock2 = redisService.decr(GoodsKey.getGoodsStock, "" + goodsId);//10 if(stock2 < 0){ localOverMap.put(goodsId, true); return Result.error(CodeMsg.SECKILL_OVER); } }
下面这个是afterPropertiesSet方法定义,每次调用都要获取所有商品并且遍历商品,这样会消耗性能吧,而且,我只是下单某一件商品,为什么在遍历中将每件商品标记为false?原本某些标记为true的商品变为false了 public void afterPropertiesSet() { List<GoodsVo> goodsVoList = goodsService.listGoodsVo(); if (goodsVoList == null) { return; } for (GoodsVo goods : goodsVoList) { redisService.set(GoodsKey.getGoodsStock, "" + goods.getId(), goods.getStockCount()); //初始化商品都是没有处理过的 localOverMap.put(goods.getId(), false); } }
public void afterPropertiesSet() { List<GoodsVo> goodsVoList = goodsService.listGoodsVo(); if (goodsVoList == null) { return; } for (GoodsVo goods : goodsVoList) { redisService.set(GoodsKey.getGoodsStock, "" + goods.getId(), goods.getStockCount()); //初始化商品都是没有处理过的 localOverMap.put(goods.getId(), false); } }
The text was updated successfully, but these errors were encountered:
我也认为这段代码有问题。不应该在缓存不足的时候,直接调用 afterPropertiesSet(),这个方法不应该直接调用。建议:另外写一个方法,只刷新当前商品即可。
Sorry, something went wrong.
No branches or pull requests
秒杀下单时的一段代码:
//预减库存 long stock = redisService.decr(GoodsKey.getGoodsStock, "" + goodsId);//10 if (stock < 0) { afterPropertiesSet(); long stock2 = redisService.decr(GoodsKey.getGoodsStock, "" + goodsId);//10 if(stock2 < 0){ localOverMap.put(goodsId, true); return Result.error(CodeMsg.SECKILL_OVER); } }
下面这个是afterPropertiesSet方法定义,每次调用都要获取所有商品并且遍历商品,这样会消耗性能吧,而且,我只是下单某一件商品,为什么在遍历中将每件商品标记为false?原本某些标记为true的商品变为false了
public void afterPropertiesSet() { List<GoodsVo> goodsVoList = goodsService.listGoodsVo(); if (goodsVoList == null) { return; } for (GoodsVo goods : goodsVoList) { redisService.set(GoodsKey.getGoodsStock, "" + goods.getId(), goods.getStockCount()); //初始化商品都是没有处理过的 localOverMap.put(goods.getId(), false); } }
The text was updated successfully, but these errors were encountered: