PromotionInfo promotionInfo = null;
PromotionInfoResponse response = new PromotionInfoResponse();
String getSubmitRef = UUID.randomUUID().toString();
lock.lock();
try {
promotionInfo = promotionInfoMapper.selectByOne(listExcludeUuid());
if (promotionInfo == null) {
log.warn("promotion getOneTask fail,there is no task. agentName={},time={}", agentName, new Date());
return null;
} else {
Long promotionInfoId = promotionInfo.getId();
SessionCallback<Object> callback = new SessionCallback<Object>() {
@Override
public Object execute(RedisOperations operations) throws DataAccessException {
operations.multi();
operations.opsForValue().set(RedisKey.PROMOTION_INFO_CHECKING_TASK_PREFIX.getKey() + promotionInfoId, Long.toString(promotionInfoId), RedisKey.PROMOTION_INFO_CHECKING_TASK_PREFIX.getExpiration(), TimeUnit.SECONDS);
operations.opsForValue().set(RedisKey.PROMOTION_TASK_GET_SUBMIT_REF_PREFIX.getKey()+ promotionInfoId, getSubmitRef, RedisKey.PROMOTION_TASK_GET_SUBMIT_REF_PREFIX.getExpiration(),TimeUnit.SECONDS);
operations.opsForValue().set(RedisKey.PROMOTION_INFO_CHECKING_AGENT_PREFIX.getKey()+ agentName, Long.toString(promotionInfoId), RedisKey.PROMOTION_INFO_CHECKING_AGENT_PREFIX.getExpiration(),TimeUnit.SECONDS);
return operations.exec();
}
};
redisTemplate.execute(callback);
}
} finally {
lock.unlock();
}
PromotionInfoHistory promotionInfoHistory = new PromotionInfoHistory();
BeanUtils.copyProperties(promotionInfo, response);
BeanUtils.copyProperties(promotionInfo, promotionInfoHistory);
recordHistory(promotionInfo, agentName, EnumHistoryEventCode.GET_TASK, getSubmitRef);
return response;
Lock锁为单机锁,在分布式下面会有问题