From c3ce2bc5d069ba57309567aee4ae418bc0cf75ed Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 17 三月 2023 13:22:05 +0800
Subject: [PATCH] 优化异常处理以及级联设备状态查询

---
 src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java |   71 +++++++++++++++++++----------------
 1 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
index 749dddd..d8270f1 100644
--- a/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
+++ b/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
@@ -1,13 +1,12 @@
 package com.genersoft.iot.vmp.utils.redis;
 
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-
-import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson2.JSONObject;
 import com.genersoft.iot.vmp.utils.SpringBeanFactory;
-import gov.nist.javax.sip.stack.UDPMessageChannel;
 import org.springframework.data.redis.core.*;
 import org.springframework.util.CollectionUtils;
+
+import java.util.*;
+import java.util.concurrent.TimeUnit;
 
 /**    
  * Redis宸ュ叿绫�
@@ -39,7 +38,7 @@
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -67,7 +66,7 @@
         try {
             return redisTemplate.hasKey(key);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -92,7 +91,7 @@
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -125,7 +124,7 @@
             redisTemplate.opsForValue().set(key, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -149,7 +148,7 @@
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -227,7 +226,7 @@
             redisTemplate.opsForHash().putAll(key, map);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -239,7 +238,7 @@
      * @param time 鏃堕棿
      * @return true / false
      */
-    public static boolean hmset(String key, Map<Object, Object> map, long time) {
+    public static boolean hmset(String key, Map<?, ?> map, long time) {
         if (redisTemplate == null) {
             redisTemplate = SpringBeanFactory.getBean("redisTemplate");
         }
@@ -250,7 +249,7 @@
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -270,7 +269,7 @@
             redisTemplate.opsForHash().put(key, item, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -294,7 +293,7 @@
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -366,7 +365,7 @@
         try {
             return redisTemplate.opsForSet().members(key);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return null;
         }
     }
@@ -384,7 +383,7 @@
         try {
             return redisTemplate.opsForSet().isMember(key, value);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -402,7 +401,7 @@
         try {
             return redisTemplate.opsForSet().add(key, values);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return 0;
         }
     }
@@ -425,7 +424,7 @@
             }
             return count;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return 0;
         }
     }
@@ -442,7 +441,7 @@
         try {
             return redisTemplate.opsForSet().size(key);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return 0;
         }
     }
@@ -460,7 +459,7 @@
         try {
             return redisTemplate.opsForSet().remove(key, values);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return 0;
         }
     }
@@ -626,7 +625,7 @@
         try {
             return redisTemplate.opsForList().range(key, start, end);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return null;
         }
     }
@@ -643,7 +642,7 @@
         try {
             return redisTemplate.opsForList().size(key);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return 0;
         }
     }
@@ -663,7 +662,7 @@
         try {
             return redisTemplate.opsForList().index(key, index);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return null;
         }
     }
@@ -682,7 +681,7 @@
             redisTemplate.opsForList().rightPush(key, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -705,7 +704,7 @@
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -724,7 +723,7 @@
             redisTemplate.opsForList().rightPushAll(key, values);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -747,7 +746,7 @@
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -767,7 +766,7 @@
             redisTemplate.opsForList().set(key, index, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return false;
         }
     }
@@ -788,7 +787,7 @@
         try {
             return redisTemplate.opsForList().remove(key, count, value);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return 0;
         }
     }
@@ -830,7 +829,7 @@
             Set<String> set = redisTemplate.keys(key);
             return new ArrayList<>(set);
         } catch (Exception e) {
-            e.printStackTrace();
+            logger.error("鏈鐞嗙殑寮傚父 ", e);
             return null;
         }
     }
@@ -855,7 +854,7 @@
 //            //鍏抽棴cursor
 //            cursor.close();
 //        } catch (Exception e) {
-//            e.printStackTrace();
+//            logger.error("鏈鐞嗙殑寮傚父 ", e);
 //        }
 //        return result;
 //    }
@@ -882,7 +881,13 @@
 
         return new ArrayList<>(resultKeys);
     }
-
+    public static List<Object> scan2(String query) {
+        if (redisTemplate == null) {
+            redisTemplate = SpringBeanFactory.getBean("redisTemplate");
+        }
+        Set<String> keys = redisTemplate.keys(query);
+        return new ArrayList<>(keys);
+    }
     //    ============================== 娑堟伅鍙戦�佷笌璁㈤槄 ==============================
     public static void convertAndSend(String channel, JSONObject msg) {
         if (redisTemplate == null) {

--
Gitblit v1.8.0