From 6595bbc8284995c7fcf75c6dab7650ed9a628bc4 Mon Sep 17 00:00:00 2001 From: yuanye <418471657@qq.com> Date: Mon, 27 May 2024 15:47:33 +0800 Subject: [PATCH] Changes --- .../com/hfkj/service/goods/impl/GoodsMsgServiceImpl.java | 6 ++++-- .../com/hfkj/service/goods/impl/GoodsSpecsServiceImpl.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/service/src/main/java/com/hfkj/service/goods/impl/GoodsMsgServiceImpl.java b/service/src/main/java/com/hfkj/service/goods/impl/GoodsMsgServiceImpl.java index 176f85a..ed7f310 100644 --- a/service/src/main/java/com/hfkj/service/goods/impl/GoodsMsgServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/goods/impl/GoodsMsgServiceImpl.java @@ -107,10 +107,12 @@ public class GoodsMsgServiceImpl implements GoodsMsgService { public void editSaleNum(Long goodsId, Integer num , Integer type) { String key = "GOODS" + goodsId; + // 分布式锁占坑 + Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, goodsId); + try { - // 分布式锁占坑 - Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, goodsId); + System.out.println("==========================================================lock" + lock); GoodsMsg goodsMsg = queryDetail(goodsId); System.out.println("==========================================================goodsMsg" + goodsMsg); diff --git a/service/src/main/java/com/hfkj/service/goods/impl/GoodsSpecsServiceImpl.java b/service/src/main/java/com/hfkj/service/goods/impl/GoodsSpecsServiceImpl.java index 7c50f7b..83b0fc6 100644 --- a/service/src/main/java/com/hfkj/service/goods/impl/GoodsSpecsServiceImpl.java +++ b/service/src/main/java/com/hfkj/service/goods/impl/GoodsSpecsServiceImpl.java @@ -102,10 +102,10 @@ public class GoodsSpecsServiceImpl implements GoodsSpecsService { String key = "GOODS_STOCK_NUM"; GoodsSpecs goodsSpecs = queryDetailByGoodsId(specsId); + // 分布式锁占坑 + Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, specsId); try { - // 分布式锁占坑 - Boolean lock = redisTemplate.opsForValue().setIfAbsent(key, specsId); if(Boolean.TRUE.equals(lock)) {