mirror of
https://gitee.com/dromara/RuoYi-Cloud-Plus.git
synced 2025-09-09 21:59:22 +00:00
update 优化 限流注解增加固定清理时间
This commit is contained in:
@@ -38,4 +38,10 @@ public @interface RateLimiter {
|
||||
* 提示消息 支持国际化 格式为 {code}
|
||||
*/
|
||||
String message() default "{rate.limiter.message}";
|
||||
|
||||
/**
|
||||
* 限流策略超时时间 默认一天(策略存活时间 会清除已存在的策略数据)
|
||||
*/
|
||||
int timeout() default 86400;
|
||||
|
||||
}
|
||||
|
@@ -54,13 +54,14 @@ public class RateLimiterAspect {
|
||||
public void doBefore(JoinPoint point, RateLimiter rateLimiter) {
|
||||
int time = rateLimiter.time();
|
||||
int count = rateLimiter.count();
|
||||
int timeout = rateLimiter.timeout();
|
||||
try {
|
||||
String combineKey = getCombineKey(rateLimiter, point);
|
||||
RateType rateType = RateType.OVERALL;
|
||||
if (rateLimiter.limitType() == LimitType.CLUSTER) {
|
||||
rateType = RateType.PER_CLIENT;
|
||||
}
|
||||
long number = RedisUtils.rateLimiter(combineKey, rateType, count, time);
|
||||
long number = RedisUtils.rateLimiter(combineKey, rateType, count, time, timeout);
|
||||
if (number == -1) {
|
||||
String message = rateLimiter.message();
|
||||
if (StringUtils.startsWith(message, "{") && StringUtils.endsWith(message, "}")) {
|
||||
|
Reference in New Issue
Block a user