Commit d47902bdca2eb772c974803a5bd72e917a294b39

Authored by 648540858
1 parent 9e2630ee

启动时redis未连接导致无法启动

src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
@@ -20,7 +20,6 @@ import org.springframework.stereotype.Service; @@ -20,7 +20,6 @@ import org.springframework.stereotype.Service;
20 import org.springframework.transaction.TransactionDefinition; 20 import org.springframework.transaction.TransactionDefinition;
21 import org.springframework.transaction.TransactionStatus; 21 import org.springframework.transaction.TransactionStatus;
22 import org.springframework.util.ObjectUtils; 22 import org.springframework.util.ObjectUtils;
23 -import org.springframework.util.StringUtils;  
24 23
25 import com.alibaba.fastjson.JSON; 24 import com.alibaba.fastjson.JSON;
26 import com.alibaba.fastjson.JSONArray; 25 import com.alibaba.fastjson.JSONArray;
@@ -40,7 +39,6 @@ import com.genersoft.iot.vmp.service.bean.SSRCInfo; @@ -40,7 +39,6 @@ import com.genersoft.iot.vmp.service.bean.SSRCInfo;
40 import com.genersoft.iot.vmp.storager.dao.MediaServerMapper; 39 import com.genersoft.iot.vmp.storager.dao.MediaServerMapper;
41 import com.genersoft.iot.vmp.utils.DateUtil; 40 import com.genersoft.iot.vmp.utils.DateUtil;
42 import com.genersoft.iot.vmp.utils.redis.RedisUtil; 41 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
43 -import com.genersoft.iot.vmp.vmanager.bean.WVPResult;  
44 42
45 import okhttp3.OkHttpClient; 43 import okhttp3.OkHttpClient;
46 import okhttp3.Request; 44 import okhttp3.Request;
@@ -135,7 +133,7 @@ public class MediaServerServiceImpl implements IMediaServerService { @@ -135,7 +133,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
135 logger.info("media server [ {} ] ssrcConfig is null", mediaServerItem.getId()); 133 logger.info("media server [ {} ] ssrcConfig is null", mediaServerItem.getId());
136 return null; 134 return null;
137 }else { 135 }else {
138 - String ssrc = null; 136 + String ssrc;
139 if (presetSsrc != null) { 137 if (presetSsrc != null) {
140 ssrc = presetSsrc; 138 ssrc = presetSsrc;
141 }else { 139 }else {
@@ -497,7 +495,7 @@ public class MediaServerServiceImpl implements IMediaServerService { @@ -497,7 +495,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
497 } 495 }
498 496
499 // 获取分数最低的,及并发最低的 497 // 获取分数最低的,及并发最低的
500 - Set<Object> objects = RedisUtil.ZRange(key, 0, -1); 498 + Set<Object> objects = RedisUtil.zRange(key, 0, -1);
501 ArrayList<Object> mediaServerObjectS = new ArrayList<>(objects); 499 ArrayList<Object> mediaServerObjectS = new ArrayList<>(objects);
502 500
503 String mediaServerId = (String)mediaServerObjectS.get(0); 501 String mediaServerId = (String)mediaServerObjectS.get(0);
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -21,6 +21,7 @@ import com.genersoft.iot.vmp.utils.redis.RedisUtil; @@ -21,6 +21,7 @@ import com.genersoft.iot.vmp.utils.redis.RedisUtil;
21 import org.slf4j.Logger; 21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory; 22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Autowired; 23 import org.springframework.beans.factory.annotation.Autowired;
  24 +import org.springframework.context.annotation.DependsOn;
24 import org.springframework.stereotype.Component; 25 import org.springframework.stereotype.Component;
25 26
26 import java.util.*; 27 import java.util.*;
src/main/java/com/genersoft/iot/vmp/utils/SpringBeanFactory.java
@@ -33,11 +33,11 @@ public class SpringBeanFactory implements ApplicationContextAware { @@ -33,11 +33,11 @@ public class SpringBeanFactory implements ApplicationContextAware {
33 /** 33 /**
34 * 获取对象 这里重写了bean方法,起主要作用 34 * 获取对象 这里重写了bean方法,起主要作用
35 */ 35 */
36 - public static Object getBean(String beanId) throws BeansException { 36 + public static <T> T getBean(String beanId) throws BeansException {
37 if (applicationContext == null) { 37 if (applicationContext == null) {
38 return null; 38 return null;
39 } 39 }
40 - return applicationContext.getBean(beanId); 40 + return (T) applicationContext.getBean(beanId);
41 } 41 }
42 42
43 /** 43 /**
src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
@@ -5,15 +5,13 @@ import java.util.concurrent.TimeUnit; @@ -5,15 +5,13 @@ import java.util.concurrent.TimeUnit;
5 5
6 import com.alibaba.fastjson.JSONObject; 6 import com.alibaba.fastjson.JSONObject;
7 import com.genersoft.iot.vmp.utils.SpringBeanFactory; 7 import com.genersoft.iot.vmp.utils.SpringBeanFactory;
8 -import org.springframework.beans.factory.annotation.Autowired;  
9 import org.springframework.data.redis.core.*; 8 import org.springframework.data.redis.core.*;
10 -import org.springframework.stereotype.Component;  
11 import org.springframework.util.CollectionUtils; 9 import org.springframework.util.CollectionUtils;
12 10
13 /** 11 /**
14 - * @description:Redis工具类  
15 - * @author: swwheihei  
16 - * @date: 2020年5月6日 下午8:27:29 12 + * Redis工具类
  13 + * @author swwheihei
  14 + * @date 2020年5月6日 下午8:27:29
17 */ 15 */
18 @SuppressWarnings(value = {"rawtypes", "unchecked"}) 16 @SuppressWarnings(value = {"rawtypes", "unchecked"})
19 public class RedisUtil { 17 public class RedisUtil {
@@ -21,9 +19,9 @@ public class RedisUtil { @@ -21,9 +19,9 @@ public class RedisUtil {
21 private static RedisTemplate redisTemplate; 19 private static RedisTemplate redisTemplate;
22 20
23 static { 21 static {
24 - redisTemplate = (RedisTemplate)SpringBeanFactory.getBean("redisTemplate"); 22 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
25 } 23 }
26 - 24 +
27 /** 25 /**
28 * 指定缓存失效时间 26 * 指定缓存失效时间
29 * @param key 键 27 * @param key 键
@@ -31,6 +29,9 @@ public class RedisUtil { @@ -31,6 +29,9 @@ public class RedisUtil {
31 * @return true / false 29 * @return true / false
32 */ 30 */
33 public static boolean expire(String key, long time) { 31 public static boolean expire(String key, long time) {
  32 + if (redisTemplate == null) {
  33 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  34 + }
34 try { 35 try {
35 if (time > 0) { 36 if (time > 0) {
36 redisTemplate.expire(key, time, TimeUnit.SECONDS); 37 redisTemplate.expire(key, time, TimeUnit.SECONDS);
@@ -45,9 +46,11 @@ public class RedisUtil { @@ -45,9 +46,11 @@ public class RedisUtil {
45 /** 46 /**
46 * 根据 key 获取过期时间 47 * 根据 key 获取过期时间
47 * @param key 键 48 * @param key 键
48 - * @return  
49 */ 49 */
50 public static long getExpire(String key) { 50 public static long getExpire(String key) {
  51 + if (redisTemplate == null) {
  52 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  53 + }
51 return redisTemplate.getExpire(key, TimeUnit.SECONDS); 54 return redisTemplate.getExpire(key, TimeUnit.SECONDS);
52 } 55 }
53 56
@@ -57,6 +60,9 @@ public class RedisUtil { @@ -57,6 +60,9 @@ public class RedisUtil {
57 * @return true / false 60 * @return true / false
58 */ 61 */
59 public static boolean hasKey(String key) { 62 public static boolean hasKey(String key) {
  63 + if (redisTemplate == null) {
  64 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  65 + }
60 try { 66 try {
61 return redisTemplate.hasKey(key); 67 return redisTemplate.hasKey(key);
62 } catch (Exception e) { 68 } catch (Exception e) {
@@ -71,6 +77,9 @@ public class RedisUtil { @@ -71,6 +77,9 @@ public class RedisUtil {
71 * @param key 键(一个或者多个) 77 * @param key 键(一个或者多个)
72 */ 78 */
73 public static boolean del(String... key) { 79 public static boolean del(String... key) {
  80 + if (redisTemplate == null) {
  81 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  82 + }
74 try { 83 try {
75 if (key != null && key.length > 0) { 84 if (key != null && key.length > 0) {
76 if (key.length == 1) { 85 if (key.length == 1) {
@@ -95,6 +104,9 @@ public class RedisUtil { @@ -95,6 +104,9 @@ public class RedisUtil {
95 * @return 值 104 * @return 值
96 */ 105 */
97 public static Object get(String key) { 106 public static Object get(String key) {
  107 + if (redisTemplate == null) {
  108 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  109 + }
98 return key == null ? null : redisTemplate.opsForValue().get(key); 110 return key == null ? null : redisTemplate.opsForValue().get(key);
99 } 111 }
100 112
@@ -105,6 +117,9 @@ public class RedisUtil { @@ -105,6 +117,9 @@ public class RedisUtil {
105 * @return true / false 117 * @return true / false
106 */ 118 */
107 public static boolean set(String key, Object value) { 119 public static boolean set(String key, Object value) {
  120 + if (redisTemplate == null) {
  121 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  122 + }
108 try { 123 try {
109 redisTemplate.opsForValue().set(key, value); 124 redisTemplate.opsForValue().set(key, value);
110 return true; 125 return true;
@@ -122,6 +137,9 @@ public class RedisUtil { @@ -122,6 +137,9 @@ public class RedisUtil {
122 * @return true / false 137 * @return true / false
123 */ 138 */
124 public static boolean set(String key, Object value, long time) { 139 public static boolean set(String key, Object value, long time) {
  140 + if (redisTemplate == null) {
  141 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  142 + }
125 try { 143 try {
126 if (time > 0) { 144 if (time > 0) {
127 redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS); 145 redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
@@ -142,6 +160,9 @@ public class RedisUtil { @@ -142,6 +160,9 @@ public class RedisUtil {
142 * @return 160 * @return
143 */ 161 */
144 public static long incr(String key, long delta) { 162 public static long incr(String key, long delta) {
  163 + if (redisTemplate == null) {
  164 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  165 + }
145 if (delta < 0) { 166 if (delta < 0) {
146 throw new RuntimeException("递增因子必须大于 0"); 167 throw new RuntimeException("递增因子必须大于 0");
147 } 168 }
@@ -155,6 +176,9 @@ public class RedisUtil { @@ -155,6 +176,9 @@ public class RedisUtil {
155 * @return 176 * @return
156 */ 177 */
157 public static long decr(String key, long delta) { 178 public static long decr(String key, long delta) {
  179 + if (redisTemplate == null) {
  180 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  181 + }
158 if (delta < 0) { 182 if (delta < 0) {
159 throw new RuntimeException("递减因子必须大于 0"); 183 throw new RuntimeException("递减因子必须大于 0");
160 } 184 }
@@ -170,6 +194,9 @@ public class RedisUtil { @@ -170,6 +194,9 @@ public class RedisUtil {
170 * @return 值 194 * @return 值
171 */ 195 */
172 public static Object hget(String key, String item) { 196 public static Object hget(String key, String item) {
  197 + if (redisTemplate == null) {
  198 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  199 + }
173 return redisTemplate.opsForHash().get(key, item); 200 return redisTemplate.opsForHash().get(key, item);
174 } 201 }
175 202
@@ -179,6 +206,9 @@ public class RedisUtil { @@ -179,6 +206,9 @@ public class RedisUtil {
179 * @return 对应的多个键值 206 * @return 对应的多个键值
180 */ 207 */
181 public static Map<Object, Object> hmget(String key) { 208 public static Map<Object, Object> hmget(String key) {
  209 + if (redisTemplate == null) {
  210 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  211 + }
182 return redisTemplate.opsForHash().entries(key); 212 return redisTemplate.opsForHash().entries(key);
183 } 213 }
184 214
@@ -189,6 +219,9 @@ public class RedisUtil { @@ -189,6 +219,9 @@ public class RedisUtil {
189 * @return true / false 219 * @return true / false
190 */ 220 */
191 public static boolean hmset(String key, Map<Object, Object> map) { 221 public static boolean hmset(String key, Map<Object, Object> map) {
  222 + if (redisTemplate == null) {
  223 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  224 + }
192 try { 225 try {
193 redisTemplate.opsForHash().putAll(key, map); 226 redisTemplate.opsForHash().putAll(key, map);
194 return true; 227 return true;
@@ -206,6 +239,9 @@ public class RedisUtil { @@ -206,6 +239,9 @@ public class RedisUtil {
206 * @return true / false 239 * @return true / false
207 */ 240 */
208 public static boolean hmset(String key, Map<Object, Object> map, long time) { 241 public static boolean hmset(String key, Map<Object, Object> map, long time) {
  242 + if (redisTemplate == null) {
  243 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  244 + }
209 try { 245 try {
210 redisTemplate.opsForHash().putAll(key, map); 246 redisTemplate.opsForHash().putAll(key, map);
211 if (time > 0) { 247 if (time > 0) {
@@ -226,6 +262,9 @@ public class RedisUtil { @@ -226,6 +262,9 @@ public class RedisUtil {
226 * @return true / false 262 * @return true / false
227 */ 263 */
228 public static boolean hset(String key, String item, Object value) { 264 public static boolean hset(String key, String item, Object value) {
  265 + if (redisTemplate == null) {
  266 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  267 + }
229 try { 268 try {
230 redisTemplate.opsForHash().put(key, item, value); 269 redisTemplate.opsForHash().put(key, item, value);
231 return true; 270 return true;
@@ -244,6 +283,9 @@ public class RedisUtil { @@ -244,6 +283,9 @@ public class RedisUtil {
244 * @return true / false 283 * @return true / false
245 */ 284 */
246 public static boolean hset(String key, String item, Object value, long time) { 285 public static boolean hset(String key, String item, Object value, long time) {
  286 + if (redisTemplate == null) {
  287 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  288 + }
247 try { 289 try {
248 redisTemplate.opsForHash().put(key, item, value); 290 redisTemplate.opsForHash().put(key, item, value);
249 if (time > 0) { 291 if (time > 0) {
@@ -262,6 +304,9 @@ public class RedisUtil { @@ -262,6 +304,9 @@ public class RedisUtil {
262 * @param item 项(可以多个,no null) 304 * @param item 项(可以多个,no null)
263 */ 305 */
264 public static void hdel(String key, Object... item) { 306 public static void hdel(String key, Object... item) {
  307 + if (redisTemplate == null) {
  308 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  309 + }
265 redisTemplate.opsForHash().delete(key, item); 310 redisTemplate.opsForHash().delete(key, item);
266 } 311 }
267 312
@@ -272,6 +317,9 @@ public class RedisUtil { @@ -272,6 +317,9 @@ public class RedisUtil {
272 * @return true / false 317 * @return true / false
273 */ 318 */
274 public static boolean hHasKey(String key, String item) { 319 public static boolean hHasKey(String key, String item) {
  320 + if (redisTemplate == null) {
  321 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  322 + }
275 return redisTemplate.opsForHash().hasKey(key, item); 323 return redisTemplate.opsForHash().hasKey(key, item);
276 } 324 }
277 325
@@ -283,6 +331,9 @@ public class RedisUtil { @@ -283,6 +331,9 @@ public class RedisUtil {
283 * @return 331 * @return
284 */ 332 */
285 public static Double hincr(String key, String item, Double by) { 333 public static Double hincr(String key, String item, Double by) {
  334 + if (redisTemplate == null) {
  335 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  336 + }
286 return redisTemplate.opsForHash().increment(key, item, by); 337 return redisTemplate.opsForHash().increment(key, item, by);
287 } 338 }
288 339
@@ -294,6 +345,9 @@ public class RedisUtil { @@ -294,6 +345,9 @@ public class RedisUtil {
294 * @return 345 * @return
295 */ 346 */
296 public static Double hdecr(String key, String item, Double by) { 347 public static Double hdecr(String key, String item, Double by) {
  348 + if (redisTemplate == null) {
  349 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  350 + }
297 return redisTemplate.opsForHash().increment(key, item, -by); 351 return redisTemplate.opsForHash().increment(key, item, -by);
298 } 352 }
299 353
@@ -305,6 +359,9 @@ public class RedisUtil { @@ -305,6 +359,9 @@ public class RedisUtil {
305 * @return 值 359 * @return 值
306 */ 360 */
307 public static Set<Object> sGet(String key) { 361 public static Set<Object> sGet(String key) {
  362 + if (redisTemplate == null) {
  363 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  364 + }
308 try { 365 try {
309 return redisTemplate.opsForSet().members(key); 366 return redisTemplate.opsForSet().members(key);
310 } catch (Exception e) { 367 } catch (Exception e) {
@@ -320,6 +377,9 @@ public class RedisUtil { @@ -320,6 +377,9 @@ public class RedisUtil {
320 * @return true / false 377 * @return true / false
321 */ 378 */
322 public static boolean sHasKey(String key, Object value) { 379 public static boolean sHasKey(String key, Object value) {
  380 + if (redisTemplate == null) {
  381 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  382 + }
323 try { 383 try {
324 return redisTemplate.opsForSet().isMember(key, value); 384 return redisTemplate.opsForSet().isMember(key, value);
325 } catch (Exception e) { 385 } catch (Exception e) {
@@ -335,6 +395,9 @@ public class RedisUtil { @@ -335,6 +395,9 @@ public class RedisUtil {
335 * @return 成功个数 395 * @return 成功个数
336 */ 396 */
337 public static long sSet(String key, Object... values) { 397 public static long sSet(String key, Object... values) {
  398 + if (redisTemplate == null) {
  399 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  400 + }
338 try { 401 try {
339 return redisTemplate.opsForSet().add(key, values); 402 return redisTemplate.opsForSet().add(key, values);
340 } catch (Exception e) { 403 } catch (Exception e) {
@@ -351,6 +414,9 @@ public class RedisUtil { @@ -351,6 +414,9 @@ public class RedisUtil {
351 * @return 成功放入个数 414 * @return 成功放入个数
352 */ 415 */
353 public static long sSet(String key, long time, Object... values) { 416 public static long sSet(String key, long time, Object... values) {
  417 + if (redisTemplate == null) {
  418 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  419 + }
354 try { 420 try {
355 long count = redisTemplate.opsForSet().add(key, values); 421 long count = redisTemplate.opsForSet().add(key, values);
356 if (time > 0) { 422 if (time > 0) {
@@ -369,6 +435,9 @@ public class RedisUtil { @@ -369,6 +435,9 @@ public class RedisUtil {
369 * @return 长度 435 * @return 长度
370 */ 436 */
371 public static long sGetSetSize(String key) { 437 public static long sGetSetSize(String key) {
  438 + if (redisTemplate == null) {
  439 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  440 + }
372 try { 441 try {
373 return redisTemplate.opsForSet().size(key); 442 return redisTemplate.opsForSet().size(key);
374 } catch (Exception e) { 443 } catch (Exception e) {
@@ -384,6 +453,9 @@ public class RedisUtil { @@ -384,6 +453,9 @@ public class RedisUtil {
384 * @return 成功移除个数 453 * @return 成功移除个数
385 */ 454 */
386 public static long setRemove(String key, Object... values) { 455 public static long setRemove(String key, Object... values) {
  456 + if (redisTemplate == null) {
  457 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  458 + }
387 try { 459 try {
388 return redisTemplate.opsForSet().remove(key, values); 460 return redisTemplate.opsForSet().remove(key, values);
389 } catch (Exception e) { 461 } catch (Exception e) {
@@ -401,6 +473,9 @@ public class RedisUtil { @@ -401,6 +473,9 @@ public class RedisUtil {
401 * @param score 473 * @param score
402 */ 474 */
403 public static void zAdd(Object key, Object value, double score) { 475 public static void zAdd(Object key, Object value, double score) {
  476 + if (redisTemplate == null) {
  477 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  478 + }
404 redisTemplate.opsForZSet().add(key, value, score); 479 redisTemplate.opsForZSet().add(key, value, score);
405 } 480 }
406 481
@@ -411,6 +486,9 @@ public class RedisUtil { @@ -411,6 +486,9 @@ public class RedisUtil {
411 * @param value 486 * @param value
412 */ 487 */
413 public static void zRemove(Object key, Object value) { 488 public static void zRemove(Object key, Object value) {
  489 + if (redisTemplate == null) {
  490 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  491 + }
414 redisTemplate.opsForZSet().remove(key, value); 492 redisTemplate.opsForZSet().remove(key, value);
415 } 493 }
416 494
@@ -422,6 +500,9 @@ public class RedisUtil { @@ -422,6 +500,9 @@ public class RedisUtil {
422 * @param delta -1 表示减 1 表示加1 500 * @param delta -1 表示减 1 表示加1
423 */ 501 */
424 public static Double zIncrScore(Object key, Object value, double delta) { 502 public static Double zIncrScore(Object key, Object value, double delta) {
  503 + if (redisTemplate == null) {
  504 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  505 + }
425 return redisTemplate.opsForZSet().incrementScore(key, value, delta); 506 return redisTemplate.opsForZSet().incrementScore(key, value, delta);
426 } 507 }
427 508
@@ -433,6 +514,9 @@ public class RedisUtil { @@ -433,6 +514,9 @@ public class RedisUtil {
433 * @return 514 * @return
434 */ 515 */
435 public static Double zScore(Object key, Object value) { 516 public static Double zScore(Object key, Object value) {
  517 + if (redisTemplate == null) {
  518 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  519 + }
436 return redisTemplate.opsForZSet().score(key, value); 520 return redisTemplate.opsForZSet().score(key, value);
437 } 521 }
438 522
@@ -444,6 +528,9 @@ public class RedisUtil { @@ -444,6 +528,9 @@ public class RedisUtil {
444 * @return 528 * @return
445 */ 529 */
446 public static Long zRank(Object key, Object value) { 530 public static Long zRank(Object key, Object value) {
  531 + if (redisTemplate == null) {
  532 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  533 + }
447 return redisTemplate.opsForZSet().rank(key, value); 534 return redisTemplate.opsForZSet().rank(key, value);
448 } 535 }
449 536
@@ -454,6 +541,9 @@ public class RedisUtil { @@ -454,6 +541,9 @@ public class RedisUtil {
454 * @return 541 * @return
455 */ 542 */
456 public static Long zSize(Object key) { 543 public static Long zSize(Object key) {
  544 + if (redisTemplate == null) {
  545 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  546 + }
457 return redisTemplate.opsForZSet().zCard(key); 547 return redisTemplate.opsForZSet().zCard(key);
458 } 548 }
459 549
@@ -467,7 +557,10 @@ public class RedisUtil { @@ -467,7 +557,10 @@ public class RedisUtil {
467 * @param end 557 * @param end
468 * @return 558 * @return
469 */ 559 */
470 - public static Set<Object> ZRange(Object key, int start, int end) { 560 + public static Set<Object> zRange(Object key, int start, int end) {
  561 + if (redisTemplate == null) {
  562 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  563 + }
471 return redisTemplate.opsForZSet().range(key, start, end); 564 return redisTemplate.opsForZSet().range(key, start, end);
472 } 565 }
473 /** 566 /**
@@ -479,6 +572,9 @@ public class RedisUtil { @@ -479,6 +572,9 @@ public class RedisUtil {
479 * @return 572 * @return
480 */ 573 */
481 public static Set<ZSetOperations.TypedTuple<String>> zRangeWithScore(Object key, int start, int end) { 574 public static Set<ZSetOperations.TypedTuple<String>> zRangeWithScore(Object key, int start, int end) {
  575 + if (redisTemplate == null) {
  576 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  577 + }
482 return redisTemplate.opsForZSet().rangeWithScores(key, start, end); 578 return redisTemplate.opsForZSet().rangeWithScores(key, start, end);
483 } 579 }
484 /** 580 /**
@@ -492,6 +588,9 @@ public class RedisUtil { @@ -492,6 +588,9 @@ public class RedisUtil {
492 * @return 588 * @return
493 */ 589 */
494 public static Set<String> zRevRange(Object key, int start, int end) { 590 public static Set<String> zRevRange(Object key, int start, int end) {
  591 + if (redisTemplate == null) {
  592 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  593 + }
495 return redisTemplate.opsForZSet().reverseRange(key, start, end); 594 return redisTemplate.opsForZSet().reverseRange(key, start, end);
496 } 595 }
497 /** 596 /**
@@ -503,6 +602,9 @@ public class RedisUtil { @@ -503,6 +602,9 @@ public class RedisUtil {
503 * @return 602 * @return
504 */ 603 */
505 public static Set<String> zSortRange(Object key, int min, int max) { 604 public static Set<String> zSortRange(Object key, int min, int max) {
  605 + if (redisTemplate == null) {
  606 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  607 + }
506 return redisTemplate.opsForZSet().rangeByScore(key, min, max); 608 return redisTemplate.opsForZSet().rangeByScore(key, min, max);
507 } 609 }
508 610
@@ -517,6 +619,9 @@ public class RedisUtil { @@ -517,6 +619,9 @@ public class RedisUtil {
517 * @return 619 * @return
518 */ 620 */
519 public static List<Object> lGet(String key, long start, long end) { 621 public static List<Object> lGet(String key, long start, long end) {
  622 + if (redisTemplate == null) {
  623 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  624 + }
520 try { 625 try {
521 return redisTemplate.opsForList().range(key, start, end); 626 return redisTemplate.opsForList().range(key, start, end);
522 } catch (Exception e) { 627 } catch (Exception e) {
@@ -531,6 +636,9 @@ public class RedisUtil { @@ -531,6 +636,9 @@ public class RedisUtil {
531 * @return 长度 636 * @return 长度
532 */ 637 */
533 public static long lGetListSize(String key) { 638 public static long lGetListSize(String key) {
  639 + if (redisTemplate == null) {
  640 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  641 + }
534 try { 642 try {
535 return redisTemplate.opsForList().size(key); 643 return redisTemplate.opsForList().size(key);
536 } catch (Exception e) { 644 } catch (Exception e) {
@@ -548,6 +656,9 @@ public class RedisUtil { @@ -548,6 +656,9 @@ public class RedisUtil {
548 * @return 值 656 * @return 值
549 */ 657 */
550 public static Object lGetIndex(String key, long index) { 658 public static Object lGetIndex(String key, long index) {
  659 + if (redisTemplate == null) {
  660 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  661 + }
551 try { 662 try {
552 return redisTemplate.opsForList().index(key, index); 663 return redisTemplate.opsForList().index(key, index);
553 } catch (Exception e) { 664 } catch (Exception e) {
@@ -563,6 +674,9 @@ public class RedisUtil { @@ -563,6 +674,9 @@ public class RedisUtil {
563 * @return true / false 674 * @return true / false
564 */ 675 */
565 public static boolean lSet(String key, Object value) { 676 public static boolean lSet(String key, Object value) {
  677 + if (redisTemplate == null) {
  678 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  679 + }
566 try { 680 try {
567 redisTemplate.opsForList().rightPush(key, value); 681 redisTemplate.opsForList().rightPush(key, value);
568 return true; 682 return true;
@@ -580,6 +694,9 @@ public class RedisUtil { @@ -580,6 +694,9 @@ public class RedisUtil {
580 * @return true / false 694 * @return true / false
581 */ 695 */
582 public static boolean lSet(String key, Object value, long time) { 696 public static boolean lSet(String key, Object value, long time) {
  697 + if (redisTemplate == null) {
  698 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  699 + }
583 try { 700 try {
584 redisTemplate.opsForList().rightPush(key, value); 701 redisTemplate.opsForList().rightPush(key, value);
585 if (time > 0) { 702 if (time > 0) {
@@ -599,6 +716,9 @@ public class RedisUtil { @@ -599,6 +716,9 @@ public class RedisUtil {
599 * @return true / false 716 * @return true / false
600 */ 717 */
601 public static boolean lSetList(String key, List<Object> values) { 718 public static boolean lSetList(String key, List<Object> values) {
  719 + if (redisTemplate == null) {
  720 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  721 + }
602 try { 722 try {
603 redisTemplate.opsForList().rightPushAll(key, values); 723 redisTemplate.opsForList().rightPushAll(key, values);
604 return true; 724 return true;
@@ -616,6 +736,9 @@ public class RedisUtil { @@ -616,6 +736,9 @@ public class RedisUtil {
616 * @return true / false 736 * @return true / false
617 */ 737 */
618 public static boolean lSetList(String key, List<Object> values, long time) { 738 public static boolean lSetList(String key, List<Object> values, long time) {
  739 + if (redisTemplate == null) {
  740 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  741 + }
619 try { 742 try {
620 redisTemplate.opsForList().rightPushAll(key, values); 743 redisTemplate.opsForList().rightPushAll(key, values);
621 if (time > 0) { 744 if (time > 0) {
@@ -636,6 +759,9 @@ public class RedisUtil { @@ -636,6 +759,9 @@ public class RedisUtil {
636 * @return true / false 759 * @return true / false
637 */ 760 */
638 public static boolean lUpdateIndex(String key, long index, Object value) { 761 public static boolean lUpdateIndex(String key, long index, Object value) {
  762 + if (redisTemplate == null) {
  763 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  764 + }
639 try { 765 try {
640 redisTemplate.opsForList().set(key, index, value); 766 redisTemplate.opsForList().set(key, index, value);
641 return true; 767 return true;
@@ -655,6 +781,9 @@ public class RedisUtil { @@ -655,6 +781,9 @@ public class RedisUtil {
655 * @return 781 * @return
656 */ 782 */
657 public static long lRemove(String key, long count, Object value) { 783 public static long lRemove(String key, long count, Object value) {
  784 + if (redisTemplate == null) {
  785 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  786 + }
658 try { 787 try {
659 return redisTemplate.opsForList().remove(key, count, value); 788 return redisTemplate.opsForList().remove(key, count, value);
660 } catch (Exception e) { 789 } catch (Exception e) {
@@ -669,6 +798,9 @@ public class RedisUtil { @@ -669,6 +798,9 @@ public class RedisUtil {
669 * @return 798 * @return
670 */ 799 */
671 public static Object lLeftPop(String key) { 800 public static Object lLeftPop(String key) {
  801 + if (redisTemplate == null) {
  802 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  803 + }
672 return redisTemplate.opsForList().leftPop(key); 804 return redisTemplate.opsForList().leftPop(key);
673 } 805 }
674 806
@@ -678,6 +810,9 @@ public class RedisUtil { @@ -678,6 +810,9 @@ public class RedisUtil {
678 * @return 810 * @return
679 */ 811 */
680 public static Object lrightPop(String key) { 812 public static Object lrightPop(String key) {
  813 + if (redisTemplate == null) {
  814 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  815 + }
681 return redisTemplate.opsForList().rightPop(key); 816 return redisTemplate.opsForList().rightPop(key);
682 } 817 }
683 818
@@ -687,6 +822,9 @@ public class RedisUtil { @@ -687,6 +822,9 @@ public class RedisUtil {
687 * @return true / false 822 * @return true / false
688 */ 823 */
689 public static List<Object> keys(String key) { 824 public static List<Object> keys(String key) {
  825 + if (redisTemplate == null) {
  826 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  827 + }
690 try { 828 try {
691 Set<String> set = redisTemplate.keys(key); 829 Set<String> set = redisTemplate.keys(key);
692 return new ArrayList<>(set); 830 return new ArrayList<>(set);
@@ -727,6 +865,9 @@ public class RedisUtil { @@ -727,6 +865,9 @@ public class RedisUtil {
727 * @return 865 * @return
728 */ 866 */
729 public static List<Object> scan(String query) { 867 public static List<Object> scan(String query) {
  868 + if (redisTemplate == null) {
  869 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  870 + }
730 Set<String> resultKeys = (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> { 871 Set<String> resultKeys = (Set<String>) redisTemplate.execute((RedisCallback<Set<String>>) connection -> {
731 ScanOptions scanOptions = ScanOptions.scanOptions().match("*" + query + "*").count(1000).build(); 872 ScanOptions scanOptions = ScanOptions.scanOptions().match("*" + query + "*").count(1000).build();
732 Cursor<byte[]> scan = connection.scan(scanOptions); 873 Cursor<byte[]> scan = connection.scan(scanOptions);
@@ -743,9 +884,10 @@ public class RedisUtil { @@ -743,9 +884,10 @@ public class RedisUtil {
743 884
744 // ============================== 消息发送与订阅 ============================== 885 // ============================== 消息发送与订阅 ==============================
745 public static void convertAndSend(String channel, JSONObject msg) { 886 public static void convertAndSend(String channel, JSONObject msg) {
746 -// redisTemplate.convertAndSend(channel, msg); 887 + if (redisTemplate == null) {
  888 + redisTemplate = SpringBeanFactory.getBean("redisTemplate");
  889 + }
747 redisTemplate.convertAndSend(channel, msg); 890 redisTemplate.convertAndSend(channel, msg);
748 -  
749 } 891 }
750 892
751 } 893 }