mirror of
https://github.com/itbaima-study/SpringBoot-Vue-Template-Jwt.git
synced 2025-05-17 21:11:15 +08:00
修复Redis限流中increment概率性重新创建一个无过期时间的新键值对(刚好过期)此时会导致用户永久被封禁(永远返回403或是401)
This commit is contained in:
parent
9eff280059
commit
8636be9a48
@ -72,8 +72,12 @@ public class FlowUtils {
|
||||
* @return 是否通过限流检查
|
||||
*/
|
||||
private boolean internalCheck(String key, int frequency, int period, LimitAction action){
|
||||
if (Boolean.TRUE.equals(template.hasKey(key))) {
|
||||
Long value = Optional.ofNullable(template.opsForValue().increment(key)).orElse(0L);
|
||||
String count = template.opsForValue().get(key);
|
||||
if (count != null) {
|
||||
long value = Optional.ofNullable(template.opsForValue().increment(key)).orElse(0L);
|
||||
int c = Integer.parseInt(count);
|
||||
if(value != c + 1)
|
||||
template.expire(key, period, TimeUnit.SECONDS);
|
||||
return action.run(value > frequency);
|
||||
} else {
|
||||
template.opsForValue().set(key, "1", period, TimeUnit.SECONDS);
|
||||
|
Loading…
x
Reference in New Issue
Block a user