Browse Source

开放锁单

wangqifan 3 years ago
parent
commit
d10e0abb3c
1 changed files with 10 additions and 10 deletions
  1. 10 10
      src/main/java/com/izouma/nineth/service/OrderService.java

+ 10 - 10
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -196,18 +196,18 @@ public class OrderService {
             throw new BusinessException("签名已过期");
         }
 
-//        if (redisTemplate.opsForValue().get(RedisKeys.BLACK_LIST + userId) != null) {
-//            throw new BusinessException("频繁操作,请稍后再试");
-//        }
+        if (redisTemplate.opsForValue().get(RedisKeys.BLACK_LIST + userId) != null) {
+            throw new BusinessException("频繁操作,请稍后再试");
+        }
         BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps(RedisKeys.LIMIT_USER + userId);
         ops.setIfAbsent(0, Duration.ofSeconds(10));
-//        long val = Optional.ofNullable(ops.increment()).orElse(0L);
-//        if (val > 5) {
-//            if (val > 10) {
-//                redisTemplate.opsForValue().set(RedisKeys.BLACK_LIST + userId, 1, Duration.ofSeconds(60 * 10));
-//            }
-//            throw new BusinessException("频繁操作,请稍后再试");
-//        }
+        long val = Optional.ofNullable(ops.increment()).orElse(0L);
+        if (val > 5) {
+            if (val > 10) {
+                redisTemplate.opsForValue().set(RedisKeys.BLACK_LIST + userId, 1, Duration.ofSeconds(60 * 10));
+            }
+            throw new BusinessException("频繁操作,请稍后再试");
+        }
 
         limitReq(collectionId);