deason 3 years ago
parent
commit
58217f2441

+ 12 - 6
examcloud-core-oe-task-api-provider/src/main/java/cn/com/qmth/examcloud/core/oe/task/controller/ExamCaptureController.java

@@ -109,22 +109,28 @@ public class ExamCaptureController extends ControllerSupport {
 
     private boolean isFaceApiLimitSeconds(String userKey) {
         String cacheKey = "$FACE_API_LIMIT:S_" + userKey;
-
         Long count = redisTemplate.opsForValue().increment(cacheKey);
-        redisTemplate.expire(cacheKey, 2, TimeUnit.SECONDS);
 
         // 限制请求:1次/2秒
-        return count > 1;
+        boolean limited = count > 1L;
+        if (!limited) {
+            redisTemplate.expire(cacheKey, 2, TimeUnit.SECONDS);
+        }
+
+        return limited;
     }
 
     private boolean isFaceApiLimitMinutes(String userKey) {
         String cacheKey = "$FACE_API_LIMIT:M_" + userKey;
-
         Long count = redisTemplate.opsForValue().increment(cacheKey);
-        redisTemplate.expire(cacheKey, 10, TimeUnit.MINUTES);
 
         // 限制请求:50次/10分钟
-        return count > 50;
+        boolean limited = count > 50L;
+        if (!limited) {
+            redisTemplate.expire(cacheKey, 10, TimeUnit.MINUTES);
+        }
+
+        return limited;
     }
 
     /**