Forráskód Böngészése

black list

(cherry picked from commit 45401aa1f8018f57af0b9443ba090922e584a37b)
xiongzhu 3 éve
szülő
commit
26488e039d
1 módosított fájl, 12 hozzáadás és 12 törlés
  1. 12 12
      src/main/java/com/izouma/nineth/service/OrderService.java

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

@@ -121,18 +121,18 @@ public class OrderService {
             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("频繁操作,请稍后再试");
-//        }
+        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("频繁操作,请稍后再试");
+        }
 
         limitReq(collectionId);