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