Authored by zhengwen.ge

update

@@ -74,32 +74,23 @@ public class RedisListCache { @@ -74,32 +74,23 @@ public class RedisListCache {
74 74
75 } 75 }
76 76
77 - public <T> void rightPushAll(String key,Collection<T> values, long timeout, TimeUnit unit) {  
78 - logger.debug("Enter rightPushAll redis list. key is {}, value is {}, timeout is {}, unit is {}", key, values, timeout, unit); 77 + public <T> void rightPushAll(String key,String value, long timeout, TimeUnit unit) {
  78 + logger.debug("Enter rightPushAll redis list. key is {}, value is {}, timeout is {}, unit is {}", key, value, timeout, unit);
79 // 如果是空列表,直接返回 79 // 如果是空列表,直接返回
80 - if (CollectionUtils.isEmpty(values)) { 80 + if (StringUtils.isEmpty(value)) {
81 return; 81 return;
82 } 82 }
83 83
84 - String cacheKey = key;  
85 // 如果获取的key为空,则说明缓存开关是关闭的 84 // 如果获取的key为空,则说明缓存开关是关闭的
86 - if (StringUtils.isEmpty(cacheKey)) { 85 + if (StringUtils.isEmpty(key)) {
87 return; 86 return;
88 } 87 }
89 try { 88 try {
90 - Collection<String> strValues = new ArrayList<String>();  
91 - for (T t : values) {  
92 - String strValue = CacheKeyHelper.value2String(t);  
93 - if (StringUtils.isEmpty(strValue)) {  
94 - continue;  
95 - }  
96 - strValues.add(strValue);  
97 - }  
98 - yhListOperations.rightPushAll(cacheKey, strValues);  
99 - yHRedisTemplate.longExpire(cacheKey, timeout, unit); 89 + yhListOperations.rightPushAll(key, value);
  90 + yHRedisTemplate.longExpire(key, timeout, unit);
100 91
101 } catch (Exception e) { 92 } catch (Exception e) {
102 - logger.warn("rightPushAll redis list operation failed. key is {}", cacheKey, e); 93 + logger.warn("rightPushAll redis list operation failed. key is {}", key, e);
103 } 94 }
104 } 95 }
105 96
@@ -22,4 +22,6 @@ public interface IPinYouService { @@ -22,4 +22,6 @@ public interface IPinYouService {
22 UnionResponse sendTrans(TransPinYouRequestBO requestBO); 22 UnionResponse sendTrans(TransPinYouRequestBO requestBO);
23 23
24 UnionResponse sendPinYou(); 24 UnionResponse sendPinYou();
  25 +
  26 + UnionResponse sendUrl(String url);
25 } 27 }
@@ -21,6 +21,7 @@ import org.springframework.stereotype.Service; @@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
21 import java.net.URLDecoder; 21 import java.net.URLDecoder;
22 import java.util.ArrayList; 22 import java.util.ArrayList;
23 import java.util.List; 23 import java.util.List;
  24 +import java.util.concurrent.TimeUnit;
24 25
25 /** 26 /**
26 * Created by yoho on 2016/11/15. 27 * Created by yoho on 2016/11/15.
@@ -38,6 +39,9 @@ public class PinYouServiceImpl implements IPinYouService { @@ -38,6 +39,9 @@ public class PinYouServiceImpl implements IPinYouService {
38 39
39 private static final String UNION_TRANS_KEY = "union:pinyou:trans"; 40 private static final String UNION_TRANS_KEY = "union:pinyou:trans";
40 41
  42 + //增加一种key,把推送失败的记录到redis里面,然后后面把失败的再重新推
  43 + private static final String UNION_SENDFAIL_KEY ="union:pinyou:sendfail";
  44 +
41 @Autowired 45 @Autowired
42 private RedisListCache redisListCache; 46 private RedisListCache redisListCache;
43 47
@@ -208,7 +212,7 @@ public class PinYouServiceImpl implements IPinYouService { @@ -208,7 +212,7 @@ public class PinYouServiceImpl implements IPinYouService {
208 return response; 212 return response;
209 } 213 }
210 214
211 - private UnionResponse sendUrl(String url) { 215 + public UnionResponse sendUrl(String url) {
212 log.info("pinyou sendUrl url is {}", url); 216 log.info("pinyou sendUrl url is {}", url);
213 try { 217 try {
214 url = URLDecoder.decode(url, "UTF-8"); 218 url = URLDecoder.decode(url, "UTF-8");
@@ -216,6 +220,7 @@ public class PinYouServiceImpl implements IPinYouService { @@ -216,6 +220,7 @@ public class PinYouServiceImpl implements IPinYouService {
216 log.info("pinyou sendUrl union success url={}, and result={}", url, pair); 220 log.info("pinyou sendUrl union success url={}, and result={}", url, pair);
217 if (pair.getLeft() != 200) { 221 if (pair.getLeft() != 200) {
218 log.warn("pinyou callback error with request={}", url); 222 log.warn("pinyou callback error with request={}", url);
  223 + redisListCache.rightPushAll(UNION_SENDFAIL_KEY,url,24, TimeUnit.HOURS);
219 return new UnionResponse(204, "callback error"); 224 return new UnionResponse(204, "callback error");
220 } 225 }
221 } catch (Exception e) { 226 } catch (Exception e) {
@@ -31,6 +31,8 @@ public class PinYouTask { @@ -31,6 +31,8 @@ public class PinYouTask {
31 31
32 private static final String UNION_TRANS_KEY = "union:pinyou:trans"; 32 private static final String UNION_TRANS_KEY = "union:pinyou:trans";
33 33
  34 + private static final String UNION_SENDFAIL_KEY ="union:pinyou:sendfail";
  35 +
34 @Resource 36 @Resource
35 IPinYouService pinYouService; 37 IPinYouService pinYouService;
36 38
@@ -57,6 +59,7 @@ public class PinYouTask { @@ -57,6 +59,7 @@ public class PinYouTask {
57 //从redis里面获取大数据的数据 59 //从redis里面获取大数据的数据
58 Long viewSize = redisListCache.size(UNION_VIEW_KEY); 60 Long viewSize = redisListCache.size(UNION_VIEW_KEY);
59 Long transSize = redisListCache.size(UNION_TRANS_KEY); 61 Long transSize = redisListCache.size(UNION_TRANS_KEY);
  62 + Long failSize = redisListCache.size(UNION_SENDFAIL_KEY);
60 List<ViewPinYouRequestBO> viewPinYouRequestBOList = new ArrayList<>(); 63 List<ViewPinYouRequestBO> viewPinYouRequestBOList = new ArrayList<>();
61 int viewSizeInt = viewSize == null ? 0 : viewSize.intValue(); 64 int viewSizeInt = viewSize == null ? 0 : viewSize.intValue();
62 int transSizeInt = transSize == null ? 0:transSize.intValue(); 65 int transSizeInt = transSize == null ? 0:transSize.intValue();
@@ -77,6 +80,13 @@ public class PinYouTask { @@ -77,6 +80,13 @@ public class PinYouTask {
77 } 80 }
78 } 81 }
79 82
  83 + if(failSize>0){
  84 + for(int i=0;i<failSize;i++){
  85 + String failUrl = redisListCache.rightPop(UNION_SENDFAIL_KEY,String.class);
  86 + pinYouService.sendUrl(failUrl);
  87 + }
  88 + }
  89 +
80 if(CollectionUtils.isNotEmpty(transPinYouRequestBOList)){ 90 if(CollectionUtils.isNotEmpty(transPinYouRequestBOList)){
81 log.info("transPinYouRequestBOList size is {}",transPinYouRequestBOList.size()); 91 log.info("transPinYouRequestBOList size is {}",transPinYouRequestBOList.size());
82 for(TransPinYouRequestBO transPinYouRequestBO:transPinYouRequestBOList){ 92 for(TransPinYouRequestBO transPinYouRequestBO:transPinYouRequestBOList){