|
|
@ -1,10 +1,10 @@
|
|
|
|
package com.java3y.austin.handler.deduplication.limit;
|
|
|
|
package com.java3y.austin.handler.deduplication.limit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
import com.java3y.austin.common.domain.TaskInfo;
|
|
|
|
import com.java3y.austin.common.domain.TaskInfo;
|
|
|
|
import com.java3y.austin.handler.deduplication.DeduplicationParam;
|
|
|
|
import com.java3y.austin.handler.deduplication.DeduplicationParam;
|
|
|
|
import com.java3y.austin.handler.deduplication.service.AbstractDeduplicationService;
|
|
|
|
import com.java3y.austin.handler.deduplication.service.AbstractDeduplicationService;
|
|
|
|
import com.java3y.austin.support.utils.RedisUtils;
|
|
|
|
import com.java3y.austin.support.utils.RedisUtils;
|
|
|
|
import com.java3y.austin.support.utils.SnowFlakeIdUtils;
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
|
|
import org.springframework.data.redis.core.script.DefaultRedisScript;
|
|
|
@ -29,7 +29,6 @@ public class SlideWindowLimitService extends AbstractLimitService {
|
|
|
|
@Autowired
|
|
|
|
@Autowired
|
|
|
|
private RedisUtils redisUtils;
|
|
|
|
private RedisUtils redisUtils;
|
|
|
|
|
|
|
|
|
|
|
|
private SnowFlakeIdUtils snowFlakeIdUtils = new SnowFlakeIdUtils(1, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private DefaultRedisScript<Long> redisScript;
|
|
|
|
private DefaultRedisScript<Long> redisScript;
|
|
|
|
|
|
|
|
|
|
|
@ -55,7 +54,7 @@ public class SlideWindowLimitService extends AbstractLimitService {
|
|
|
|
long nowTime = System.currentTimeMillis();
|
|
|
|
long nowTime = System.currentTimeMillis();
|
|
|
|
for (String receiver : taskInfo.getReceiver()) {
|
|
|
|
for (String receiver : taskInfo.getReceiver()) {
|
|
|
|
String key = LIMIT_TAG + deduplicationSingleKey(service, taskInfo, receiver);
|
|
|
|
String key = LIMIT_TAG + deduplicationSingleKey(service, taskInfo, receiver);
|
|
|
|
String scoreValue = String.valueOf(snowFlakeIdUtils.nextId());
|
|
|
|
String scoreValue = String.valueOf(IdUtil.getSnowflake().nextId());
|
|
|
|
String score = String.valueOf(nowTime);
|
|
|
|
String score = String.valueOf(nowTime);
|
|
|
|
if (redisUtils.execLimitLua(redisScript, Arrays.asList(key), String.valueOf(param.getDeduplicationTime() * 1000), score, String.valueOf(param.getCountNum()), scoreValue)) {
|
|
|
|
if (redisUtils.execLimitLua(redisScript, Arrays.asList(key), String.valueOf(param.getDeduplicationTime() * 1000), score, String.valueOf(param.getCountNum()), scoreValue)) {
|
|
|
|
filterReceiver.add(receiver);
|
|
|
|
filterReceiver.add(receiver);
|
|
|
|