fix: 优化LimitAspect中RedisScript类型及ObjUtil判断
close https://github.com/elunez/eladmin-mp/issues/47
This commit is contained in:
parent
987c5ec779
commit
c474e0f3ee
@ -15,6 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package me.zhengjie.aspect;
|
package me.zhengjie.aspect;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import me.zhengjie.annotation.Limit;
|
import me.zhengjie.annotation.Limit;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
@ -71,9 +72,9 @@ public class LimitAspect {
|
|||||||
ImmutableList<Object> keys = ImmutableList.of(StringUtils.join(limit.prefix(), "_", key, "_", request.getRequestURI().replace("/","_")));
|
ImmutableList<Object> keys = ImmutableList.of(StringUtils.join(limit.prefix(), "_", key, "_", request.getRequestURI().replace("/","_")));
|
||||||
|
|
||||||
String luaScript = buildLuaScript();
|
String luaScript = buildLuaScript();
|
||||||
RedisScript<Number> redisScript = new DefaultRedisScript<>(luaScript, Number.class);
|
RedisScript<Long> redisScript = new DefaultRedisScript<>(luaScript, Long.class);
|
||||||
Number count = redisTemplate.execute(redisScript, keys, limit.count(), limit.period());
|
Long count = redisTemplate.execute(redisScript, keys, limit.count(), limit.period());
|
||||||
if (null != count && count.intValue() <= limit.count()) {
|
if (ObjUtil.isNotNull(count) && count.intValue() <= limit.count()) {
|
||||||
logger.info("第{}次访问key为 {},描述为 [{}] 的接口", count, keys, limit.name());
|
logger.info("第{}次访问key为 {},描述为 [{}] 的接口", count, keys, limit.name());
|
||||||
return joinPoint.proceed();
|
return joinPoint.proceed();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user