update 优化冗余分隔符

This commit is contained in:
AprilWind
2026-06-04 15:08:13 +08:00
parent f52bb99419
commit e08160afb6
13 changed files with 196 additions and 197 deletions
@@ -53,7 +53,7 @@ public class RateLimiterAspect {
/**
* 在限流注解方法执行前扣减令牌,令牌不足时阻断请求。
*
* @param point 切点信息
* @param point 切点信息
* @param rateLimiter 限流注解配置
*/
@Before("@annotation(rateLimiter)")
@@ -89,7 +89,7 @@ public class RateLimiterAspect {
* 组装限流缓存键。
*
* @param rateLimiter 限流注解配置
* @param point 切点信息
* @param point 切点信息
* @return 限流缓存键
*/
private String getCombineKey(RateLimiter rateLimiter, JoinPoint point) {
@@ -100,11 +100,11 @@ public class RateLimiterAspect {
Method targetMethod = signature.getMethod();
Object[] args = point.getArgs();
MethodBasedEvaluationContext context =
new MethodBasedEvaluationContext(null, targetMethod, args, pnd);
new MethodBasedEvaluationContext(null, targetMethod, args, pnd);
context.setBeanResolver(new BeanFactoryResolver(SpringUtils.getBeanFactory()));
Expression expression;
if (StringUtils.startsWith(key, parserContext.getExpressionPrefix())
&& StringUtils.endsWith(key, parserContext.getExpressionSuffix())) {
&& StringUtils.endsWith(key, parserContext.getExpressionSuffix())) {
expression = parser.parseExpression(key, parserContext);
} else {
expression = parser.parseExpression(key);
@@ -112,13 +112,13 @@ public class RateLimiterAspect {
key = expression.getValue(context, String.class);
}
StringBuilder stringBuffer = new StringBuilder(GlobalConstants.RATE_LIMIT_KEY);
stringBuffer.append(ServletUtils.getRequest().getRequestURI()).append(":");
stringBuffer.append(ServletUtils.getRequest().getRequestURI()).append(StringUtils.COLON);
if (rateLimiter.limitType() == LimitType.IP) {
// 获取请求ip
stringBuffer.append(ServletUtils.getClientIP()).append(":");
stringBuffer.append(ServletUtils.getClientIP()).append(StringUtils.COLON);
} else if (rateLimiter.limitType() == LimitType.CLUSTER) {
// 获取客户端实例id
stringBuffer.append(RedisUtils.getClient().getId()).append(":");
stringBuffer.append(RedisUtils.getClient().getId()).append(StringUtils.COLON);
}
return stringBuffer.append(key).toString();
}
@@ -62,7 +62,7 @@ public class RepeatSubmitAspect {
// 唯一值(没有消息头则使用请求地址)
String submitKey = StringUtils.trimToEmpty(request.getHeader(SaManager.getConfig().getTokenName()));
submitKey = SecureUtil.md5(submitKey + ":" + nowParams);
submitKey = SecureUtil.md5(submitKey + StringUtils.COLON + nowParams);
// 唯一标识(指定key + url + 消息头)
String cacheRepeatKey = GlobalConstants.REPEAT_SUBMIT_KEY + url + submitKey;
if (RedisUtils.setObjectIfAbsent(cacheRepeatKey, "", Duration.ofMillis(interval))) {
@@ -163,7 +163,7 @@ public class RepeatSubmitAspect {
}
}
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|| o instanceof BindingResult;
|| o instanceof BindingResult;
}
}
@@ -21,7 +21,7 @@ public class KeyPrefixHandler implements NameMapper {
*/
public KeyPrefixHandler(String keyPrefix) {
//前缀为空 则返回空前缀
this.keyPrefix = StringUtils.isBlank(keyPrefix) ? "" : keyPrefix + ":";
this.keyPrefix = StringUtils.isBlank(keyPrefix) ? "" : keyPrefix + StringUtils.COLON;
}
/**
@@ -1,5 +1,6 @@
package org.dromara.common.redis.manager;
import org.dromara.common.core.utils.StringUtils;
import org.springframework.cache.Cache;
import java.util.concurrent.Callable;
@@ -55,7 +56,7 @@ public class CaffeineCacheDecorator implements Cache {
* @return 唯一键
*/
public String getUniqueKey(Object key) {
return name + ":" + key;
return name + StringUtils.COLON + key;
}
/**
@@ -175,7 +176,7 @@ public class CaffeineCacheDecorator implements Cache {
* 清理当前缓存命名空间下的本地一级缓存。
*/
private void clearLocalCache() {
String prefix = name + ":";
String prefix = name + StringUtils.COLON;
caffeine.asMap().keySet().removeIf(key -> key instanceof String cacheKey && cacheKey.startsWith(prefix));
}