Authored by chenchao

add log

... ... @@ -30,6 +30,7 @@ public class RedisLimitor {
private Integer threshold;
@Builder.Default
private int retry = 3;
/**
... ... @@ -48,9 +49,11 @@ public class RedisLimitor {
if (threshold <= 0 || StringUtils.isBlank(key)){
return false;
}
logger.info("enter acquire,key {} threshold {} retry {}", key, threshold, retry);
logger.info("enter RedisLimitor.tryAcquire,key {} threshold {} retry {}", key, threshold, retry);
String valueFromCache = redisTemplate.getStringRedisTemplate().opsForValue().get(key);
boolean notExisted = StringUtils.isBlank(valueFromCache);
logger.info("RedisLimitor.tryAcquire get value from cache, key {} threshold {} retry {} valueFromCache {}",
key, threshold, retry, valueFromCache);
//distributed lock by set nx
if (notExisted){
//起始设置为0
... ... @@ -78,7 +81,8 @@ public class RedisLimitor {
logger.warn("RedisLimitor.acquire over limit,key {} threshold from cache {},int val {}, config val {}", key, valueFromCache, intValFromCache, threshold);
return false;
}
logger.info("RedisLimitor.tryAcquire finish, key {} threshold {} retry {} valueFromCache {}",
key, threshold, retry, valueFromCache);
return true;
}
... ...
... ... @@ -140,7 +140,7 @@ public class MsgService {
RedisKeyBuilder rkb = CacheKeyBuilder.bidOrderNoticeKey(tabType, uid, caseId);
//use thread pool to control
Supplier<Integer> supplier = () -> sendPrdPush(uid, sellerOrderGoods, product);
executorService.submit(()->redisLimitStrategy.checkLimit(uid, storageId, rkb, noticeRuleNodeMap, supplier));
executorService.submit(()->redisLimitStrategy.limit(uid, storageId, rkb, noticeRuleNodeMap, supplier));
}
long taskCount = executorService.getTaskCount();
... ...
... ... @@ -6,6 +6,8 @@ import com.yohoufo.common.concurrent.RedisLimitor;
import com.yohoufo.msg.constants.RuleKeyType;
import com.yohoufo.msg.model.NoticeRuleNode;
import lombok.Builder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
... ... @@ -18,11 +20,12 @@ import java.util.function.Supplier;
@Service
public class RedisLimitStrategy {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private RedisConcurrentFactory redisConcurrentFactory;
public boolean checkLimit(Integer uid, Integer storageId,
public boolean limit(Integer uid, Integer storageId,
RedisKeyBuilder rkb,
Map<Integer, NoticeRuleNode> noticeRuleNodeMap,
Supplier<Integer> pushSupplier){
... ... @@ -50,6 +53,8 @@ public class RedisLimitStrategy {
}
}
logger.info("RedisLimitStrategy.limit check by all config ,uid {} sku {} result {}",
uid, storageId, result);
//所有条件都满足后,聚合处理自增
if (result){
pushSupplier.get();
... ... @@ -59,7 +64,7 @@ public class RedisLimitStrategy {
return result;
}
public CheckResultNode checkLimitBySingleRule(RedisKeyBuilder rkb, NoticeRuleNode ruleNode){
private CheckResultNode checkLimitBySingleRule(RedisKeyBuilder rkb, NoticeRuleNode ruleNode){
Integer uid = ruleNode.getUid();
TimeUnit timeUnit = ruleNode.getTimeUnit();
... ...