소스 검색

add 增加 RedisUtils 操作原子值方法

疯狂的狮子li 3 년 전
부모
커밋
b01d45cf5c
1개의 변경된 파일44개의 추가작업 그리고 0개의 파일을 삭제
  1. 44 0
      ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java

+ 44 - 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/redis/RedisUtils.java

@@ -364,6 +364,50 @@ public class RedisUtils {
         return rMap.getAll(hKeys);
     }
 
+    /**
+     * 设置原子值
+     *
+     * @param key   Redis键
+     * @param value 值
+     */
+    public static void setAtomicValue(String key, long value) {
+        RAtomicLong atomic = CLIENT.getAtomicLong(key);
+        atomic.set(value);
+    }
+
+    /**
+     * 获取原子值
+     *
+     * @param key Redis键
+     * @return 当前值
+     */
+    public static long getAtomicValue(String key) {
+        RAtomicLong atomic = CLIENT.getAtomicLong(key);
+        return atomic.get();
+    }
+
+    /**
+     * 递增原子值
+     *
+     * @param key Redis键
+     * @return 当前值
+     */
+    public static long incrAtomicValue(String key) {
+        RAtomicLong atomic = CLIENT.getAtomicLong(key);
+        return atomic.incrementAndGet();
+    }
+
+    /**
+     * 递减原子值
+     *
+     * @param key Redis键
+     * @return 当前值
+     */
+    public static long decrAtomicValue(String key) {
+        RAtomicLong atomic = CLIENT.getAtomicLong(key);
+        return atomic.decrementAndGet();
+    }
+
     /**
      * 获得缓存的基本对象列表
      *