Authored by ping

update

@@ -102,10 +102,16 @@ public class UnionServiceImpl implements IUnionService { @@ -102,10 +102,16 @@ public class UnionServiceImpl implements IUnionService {
102 // } 102 // }
103 103
104 //保存到缓存中,有效期三个小时 104 //保存到缓存中,有效期三个小时
105 - yhValueOperations.setIfAbsent(key, JSON.toJSONString(request));  
106 - DynamicIntProperty activeTime = DynamicPropertyFactory.getInstance().getIntProperty("activeTime", 3 * 60 * 60);  
107 - yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.SECONDS);  
108 - log.info("clickUnion set redis success with request={}", request); 105 + try {
  106 + yhValueOperations.setIfAbsent(key, JSON.toJSONString(request));
  107 + DynamicIntProperty activeTime = DynamicPropertyFactory.getInstance().getIntProperty("activeTime", 3 * 60 * 60);
  108 + yHRedisTemplate.longExpire(key, activeTime.get(), TimeUnit.SECONDS);
  109 + log.info("clickUnion set redis success with request={}", request);
  110 + } catch (Exception e) {
  111 + log.error("clickUnion error set redis error with request={}", request);
  112 + return new UnionResponse(204, "set redis error");
  113 + }
  114 +
109 115
110 // if (union != null) { 116 // if (union != null) {
111 // //如果90天以内,已经存在点击记录,则不需要插入或更新数据库 117 // //如果90天以内,已经存在点击记录,则不需要插入或更新数据库
@@ -156,8 +162,14 @@ public class UnionServiceImpl implements IUnionService { @@ -156,8 +162,14 @@ public class UnionServiceImpl implements IUnionService {
156 162
157 //组装redis保存的key 163 //组装redis保存的key
158 String key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd(); 164 String key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getTd();
  165 + String value = "";
  166 + try {
  167 + value = yhValueOperations.get(key);
  168 + } catch (Exception e) {
  169 + log.error("activateUnion error get redis error with request={}", request);
  170 + return new UnionResponse(204, "get redis error");
  171 + }
159 172
160 - String value = yhValueOperations.get(key);  
161 log.info("activateUnion get key={}, value={}", key, value); 173 log.info("activateUnion get key={}, value={}", key, value);
162 //如果redis中不存在存在该用户点击信息,则退出 174 //如果redis中不存在存在该用户点击信息,则退出
163 if (StringUtils.isEmpty(value)) { 175 if (StringUtils.isEmpty(value)) {