Skip to content

Commit

Permalink
2024-12-06 20:39:12
Browse files Browse the repository at this point in the history
  • Loading branch information
yingzhuo committed Dec 6, 2024
1 parent 7121a18 commit 5dfc689
Showing 1 changed file with 13 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.util.Assert;
import spring.turbo.core.AspectUtils;
import spring.turbo.core.StringSpELResolvable;
import spring.turbo.core.SpEL;
import spring.turbo.exception.RuntimeExceptionSupplier;

import java.util.Map;
Expand All @@ -20,6 +20,10 @@
@Aspect
public class AvoidRepeatedInvocationAdvice implements Ordered {

/*
* 本切面逻辑需要手工注册
*/

private final RedisOperations<String, String> redisOperations;
private final RuntimeExceptionSupplier exceptionSupplier;
private final int order;
Expand Down Expand Up @@ -49,20 +53,15 @@ public Object around(ProceedingJoinPoint joinPoint) throws Throwable {

var method = AspectUtils.getMethod(joinPoint);

var redisKey = new StringSpELResolvable() {
@Override
public String getExpression() {
return annotation.value();
}

@Override
public Map<String, ?> getVariables() {
return Map.of(
var redisKey = (String) SpEL.getValue(
annotation.value(),
null,
Map.of(
"args", joinPoint.getArgs(),
"methodName", method.getName()
);
}
}.getValue();
"method", method,
"target", joinPoint.getTarget()
)
);

var success = redisOperations.opsForValue()
.setIfAbsent(redisKey, "1", annotation.leaseTime(), annotation.leaseTimeUnit());
Expand Down

0 comments on commit 5dfc689

Please sign in to comment.