Authored by zhengwen.ge

update

... ... @@ -74,32 +74,23 @@ public class RedisListCache {
}
public <T> void rightPushAll(String key,Collection<T> values, long timeout, TimeUnit unit) {
logger.debug("Enter rightPushAll redis list. key is {}, value is {}, timeout is {}, unit is {}", key, values, timeout, unit);
public <T> void rightPushAll(String key,String value, long timeout, TimeUnit unit) {
logger.debug("Enter rightPushAll redis list. key is {}, value is {}, timeout is {}, unit is {}", key, value, timeout, unit);
// 如果是空列表,直接返回
if (CollectionUtils.isEmpty(values)) {
if (StringUtils.isEmpty(value)) {
return;
}
String cacheKey = key;
// 如果获取的key为空,则说明缓存开关是关闭的
if (StringUtils.isEmpty(cacheKey)) {
if (StringUtils.isEmpty(key)) {
return;
}
try {
Collection<String> strValues = new ArrayList<String>();
for (T t : values) {
String strValue = CacheKeyHelper.value2String(t);
if (StringUtils.isEmpty(strValue)) {
continue;
}
strValues.add(strValue);
}
yhListOperations.rightPushAll(cacheKey, strValues);
yHRedisTemplate.longExpire(cacheKey, timeout, unit);
yhListOperations.rightPushAll(key, value);
yHRedisTemplate.longExpire(key, timeout, unit);
} catch (Exception e) {
logger.warn("rightPushAll redis list operation failed. key is {}", cacheKey, e);
logger.warn("rightPushAll redis list operation failed. key is {}", key, e);
}
}
... ...
... ... @@ -22,4 +22,6 @@ public interface IPinYouService {
UnionResponse sendTrans(TransPinYouRequestBO requestBO);
UnionResponse sendPinYou();
UnionResponse sendUrl(String url);
}
... ...
... ... @@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* Created by yoho on 2016/11/15.
... ... @@ -38,6 +39,9 @@ public class PinYouServiceImpl implements IPinYouService {
private static final String UNION_TRANS_KEY = "union:pinyou:trans";
//增加一种key,把推送失败的记录到redis里面,然后后面把失败的再重新推
private static final String UNION_SENDFAIL_KEY ="union:pinyou:sendfail";
@Autowired
private RedisListCache redisListCache;
... ... @@ -208,7 +212,7 @@ public class PinYouServiceImpl implements IPinYouService {
return response;
}
private UnionResponse sendUrl(String url) {
public UnionResponse sendUrl(String url) {
log.info("pinyou sendUrl url is {}", url);
try {
url = URLDecoder.decode(url, "UTF-8");
... ... @@ -216,6 +220,7 @@ public class PinYouServiceImpl implements IPinYouService {
log.info("pinyou sendUrl union success url={}, and result={}", url, pair);
if (pair.getLeft() != 200) {
log.warn("pinyou callback error with request={}", url);
redisListCache.rightPushAll(UNION_SENDFAIL_KEY,url,24, TimeUnit.HOURS);
return new UnionResponse(204, "callback error");
}
} catch (Exception e) {
... ...
... ... @@ -31,6 +31,8 @@ public class PinYouTask {
private static final String UNION_TRANS_KEY = "union:pinyou:trans";
private static final String UNION_SENDFAIL_KEY ="union:pinyou:sendfail";
@Resource
IPinYouService pinYouService;
... ... @@ -57,6 +59,7 @@ public class PinYouTask {
//从redis里面获取大数据的数据
Long viewSize = redisListCache.size(UNION_VIEW_KEY);
Long transSize = redisListCache.size(UNION_TRANS_KEY);
Long failSize = redisListCache.size(UNION_SENDFAIL_KEY);
List<ViewPinYouRequestBO> viewPinYouRequestBOList = new ArrayList<>();
int viewSizeInt = viewSize == null ? 0 : viewSize.intValue();
int transSizeInt = transSize == null ? 0:transSize.intValue();
... ... @@ -77,6 +80,13 @@ public class PinYouTask {
}
}
if(failSize>0){
for(int i=0;i<failSize;i++){
String failUrl = redisListCache.rightPop(UNION_SENDFAIL_KEY,String.class);
pinYouService.sendUrl(failUrl);
}
}
if(CollectionUtils.isNotEmpty(transPinYouRequestBOList)){
log.info("transPinYouRequestBOList size is {}",transPinYouRequestBOList.size());
for(TransPinYouRequestBO transPinYouRequestBO:transPinYouRequestBOList){
... ...