From a7aaeabc7873a0eafb4a7ecad7f65b018b7a9bc9 Mon Sep 17 00:00:00 2001
From: sean.zhou <sean.zhou@dji.com>
Date: Fri, 24 Feb 2023 19:31:23 +0800
Subject: [PATCH] What's new? 1. Add license for dock. 2. Modify the logic corresponding to the firmware file and device type. 3. Add multiple mqtt clients options. 4. Modify the structure of the interface for obtaining the device list. 5. Fixed some issues.

---
 src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java |  114 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 95 insertions(+), 19 deletions(-)

diff --git a/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java b/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java
index f5b1066..a3e83b3 100644
--- a/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java
+++ b/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java
@@ -3,6 +3,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
 
 import java.util.List;
 import java.util.Set;
@@ -16,8 +17,12 @@
 @Component
 public class RedisOpsUtils {
 
+    private static RedisTemplate<String, Object> redisTemplate;
+
     @Autowired
-    private RedisTemplate<String, Object> redisTemplate;
+    public void setRedisTemplate(RedisTemplate<String, Object> redisTemplate) {
+        RedisOpsUtils.redisTemplate = redisTemplate;
+    }
 
     /**
      * HSET
@@ -25,7 +30,7 @@
      * @param field
      * @param value
      */
-    public void hashSet(String key, String field, Object value) {
+    public static void hashSet(String key, String field, Object value) {
         redisTemplate.opsForHash().put(key, field, value);
     }
 
@@ -35,7 +40,7 @@
      * @param field
      * @return
      */
-    public Object hashGet(String key, String field) {
+    public static Object hashGet(String key, String field) {
         return redisTemplate.opsForHash().get(key, field);
     }
 
@@ -44,7 +49,7 @@
      * @param key
      * @return
      */
-    public Set<Object> hashKeys(String key) {
+    public static Set<Object> hashKeys(String key) {
         return redisTemplate.opsForHash().keys(key);
     }
 
@@ -54,7 +59,7 @@
      * @param field
      * @return
      */
-    public boolean hashCheck(String key, String field) {
+    public static boolean hashCheck(String key, String field) {
         return redisTemplate.opsForHash().hasKey(key, field);
     }
 
@@ -64,8 +69,17 @@
      * @param fields
      * @return
      */
-    public boolean hashDel(String key, Object[] fields) {
+    public static boolean hashDel(String key, Object[] fields) {
         return redisTemplate.opsForHash().delete(key, fields) > 0;
+    }
+
+    /**
+     * HLEN
+     * @param key
+     * @return
+     */
+    public static long hashLen(String key) {
+        return redisTemplate.opsForHash().size(key);
     }
 
     /**
@@ -74,7 +88,7 @@
      * @param timeout
      * @return
      */
-    public boolean expireKey(String key, long timeout) {
+    public static boolean expireKey(String key, long timeout) {
         return redisTemplate.expire(key, timeout, TimeUnit.SECONDS);
     }
 
@@ -83,7 +97,7 @@
      * @param key
      * @param value
      */
-    public void set(String key, Object value) {
+    public static void set(String key, Object value) {
         redisTemplate.opsForValue().set(key, value);
     }
 
@@ -92,7 +106,7 @@
      * @param key
      * @return
      */
-    public Object get(String key) {
+    public static Object get(String key) {
         return redisTemplate.opsForValue().get(key);
     }
 
@@ -102,7 +116,7 @@
      * @param value
      * @param expire
      */
-    public void setWithExpire(String key, Object value, long expire) {
+    public static void setWithExpire(String key, Object value, long expire) {
         redisTemplate.opsForValue().set(key, value, expire, TimeUnit.SECONDS);
     }
 
@@ -111,7 +125,7 @@
      * @param key
      * @return
      */
-    public long getExpire(String key) {
+    public static long getExpire(String key) {
         return redisTemplate.getExpire(key, TimeUnit.SECONDS);
     }
 
@@ -120,7 +134,7 @@
      * @param key
      * @return
      */
-    public boolean checkExist(String key) {
+    public static boolean checkExist(String key) {
         return redisTemplate.hasKey(key);
     }
 
@@ -129,8 +143,8 @@
      * @param key
      * @return
      */
-    public boolean del(String key) {
-        return this.checkExist(key) && redisTemplate.delete(key);
+    public static boolean del(String key) {
+        return RedisOpsUtils.checkExist(key) && redisTemplate.delete(key);
     }
 
     /**
@@ -138,7 +152,7 @@
      * @param pattern
      * @return
      */
-    public Set<String> getAllKeys(String pattern) {
+    public static Set<String> getAllKeys(String pattern) {
         return redisTemplate.keys(pattern);
     }
 
@@ -147,7 +161,7 @@
      * @param key
      * @param value
      */
-    public void listRPush(String key, Object... value) {
+    public static void listRPush(String key, Object... value) {
         if (value.length == 0) {
             return;
         }
@@ -163,7 +177,7 @@
      * @param end
      * @return
      */
-    public List<Object> listGet(String key, long start, long end) {
+    public static List<Object> listGet(String key, long start, long end) {
         return redisTemplate.opsForList().range(key, start, end);
     }
 
@@ -172,7 +186,7 @@
      * @param key
      * @return
      */
-    public List<Object> listGetAll(String key) {
+    public static List<Object> listGetAll(String key) {
         return redisTemplate.opsForList().range(key, 0, -1);
     }
 
@@ -181,7 +195,69 @@
      * @param key
      * @return
      */
-    public Long listLen(String key) {
+    public static Long listLen(String key) {
         return redisTemplate.opsForList().size(key);
     }
+
+    /**
+     * ZADD
+     * @param key
+     * @param value
+     * @param score
+     */
+    public static Boolean zAdd(String key, Object value, double score) {
+        return redisTemplate.opsForZSet().add(key, value, score);
+    }
+
+    /**
+     * ZREM
+     * @param key
+     * @param value
+     */
+    public static Boolean zRemove(String key, Object... value) {
+        return redisTemplate.opsForZSet().remove(key, value) > 0;
+    }
+    /**
+     * ZRANGE
+     * @param key
+     * @param start
+     * @param end
+     * @return
+     */
+    public static Set<Object> zRange(String key, long start, long end) {
+        return redisTemplate.opsForZSet().range(key, start, end);
+    }
+
+    /**
+     * ZRANGE
+     * @param key
+     * @return
+     */
+    public static Object zGetMin(String key) {
+        Set<Object> objects = zRange(key, 0, 0);
+        if (CollectionUtils.isEmpty(objects)) {
+            return null;
+        }
+        return objects.iterator().next();
+    }
+
+    /**
+     * ZSCORE
+     * @param key
+     * @param value
+     * @return
+     */
+    public static Double zScore(String key, Object value) {
+        return redisTemplate.opsForZSet().score(key, value);
+    }
+
+    /**
+     * ZINCRBY
+     * @param key
+     * @param value
+     * @param delta
+     */
+    public static Double zIncrement(String key, Object value, double delta) {
+        return redisTemplate.opsForZSet().incrementScore(key, value, delta);
+    }
 }

--
Gitblit v1.9.3