From 8d9a2d656e4ae007590c622e5f7c228adacdca49 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Fri, 14 Jun 2024 10:11:36 +0800
Subject: [PATCH] 统一风格

---
 src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java |   70 +++++++++++++++++++++++------------
 1 files changed, 46 insertions(+), 24 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 5e329c9..a3e83b3 100644
--- a/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java
+++ b/src/main/java/com/dji/sample/component/redis/RedisOpsUtils.java
@@ -17,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
@@ -26,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);
     }
 
@@ -36,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);
     }
 
@@ -45,7 +49,7 @@
      * @param key
      * @return
      */
-    public Set<Object> hashKeys(String key) {
+    public static Set<Object> hashKeys(String key) {
         return redisTemplate.opsForHash().keys(key);
     }
 
@@ -55,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);
     }
 
@@ -65,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);
     }
 
     /**
@@ -75,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);
     }
 
@@ -84,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);
     }
 
@@ -93,7 +106,7 @@
      * @param key
      * @return
      */
-    public Object get(String key) {
+    public static Object get(String key) {
         return redisTemplate.opsForValue().get(key);
     }
 
@@ -103,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);
     }
 
@@ -112,7 +125,7 @@
      * @param key
      * @return
      */
-    public long getExpire(String key) {
+    public static long getExpire(String key) {
         return redisTemplate.getExpire(key, TimeUnit.SECONDS);
     }
 
@@ -121,7 +134,7 @@
      * @param key
      * @return
      */
-    public boolean checkExist(String key) {
+    public static boolean checkExist(String key) {
         return redisTemplate.hasKey(key);
     }
 
@@ -130,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);
     }
 
     /**
@@ -139,7 +152,7 @@
      * @param pattern
      * @return
      */
-    public Set<String> getAllKeys(String pattern) {
+    public static Set<String> getAllKeys(String pattern) {
         return redisTemplate.keys(pattern);
     }
 
@@ -148,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;
         }
@@ -164,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);
     }
 
@@ -173,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);
     }
 
@@ -182,7 +195,7 @@
      * @param key
      * @return
      */
-    public Long listLen(String key) {
+    public static Long listLen(String key) {
         return redisTemplate.opsForList().size(key);
     }
 
@@ -192,7 +205,7 @@
      * @param value
      * @param score
      */
-    public Boolean zAdd(String key, Object value, double score) {
+    public static Boolean zAdd(String key, Object value, double score) {
         return redisTemplate.opsForZSet().add(key, value, score);
     }
 
@@ -201,7 +214,7 @@
      * @param key
      * @param value
      */
-    public Boolean zRemove(String key, Object... value) {
+    public static Boolean zRemove(String key, Object... value) {
         return redisTemplate.opsForZSet().remove(key, value) > 0;
     }
     /**
@@ -211,7 +224,7 @@
      * @param end
      * @return
      */
-    public Set<Object> zRange(String key, long start, long end) {
+    public static Set<Object> zRange(String key, long start, long end) {
         return redisTemplate.opsForZSet().range(key, start, end);
     }
 
@@ -220,7 +233,7 @@
      * @param key
      * @return
      */
-    public Object zGetMin(String key) {
+    public static Object zGetMin(String key) {
         Set<Object> objects = zRange(key, 0, 0);
         if (CollectionUtils.isEmpty(objects)) {
             return null;
@@ -234,8 +247,17 @@
      * @param value
      * @return
      */
-    public Double zScore(String key, Object value) {
+    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