From 93ac75952d5d6f64256434b99c8da612fa339263 Mon Sep 17 00:00:00 2001
From: guang <guang@guang.com>
Date: 星期五, 14 六月 2024 17:10:27 +0800
Subject: [PATCH] 切加颜分支

---
 src/main/java/com/hx/redisson/config/RedissonUtil.java |   81 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 80 insertions(+), 1 deletions(-)

diff --git a/src/main/java/com/hx/redisson/config/RedissonUtil.java b/src/main/java/com/hx/redisson/config/RedissonUtil.java
index 7957e3c..2d2fbce 100644
--- a/src/main/java/com/hx/redisson/config/RedissonUtil.java
+++ b/src/main/java/com/hx/redisson/config/RedissonUtil.java
@@ -1,12 +1,13 @@
 package com.hx.redisson.config;
 
 import com.hx.redisson.manager.RedisManager;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.data.redis.core.ZSetOperations;
-import org.springframework.stereotype.Component;
 import org.springframework.util.CollectionUtils;
 
 import java.util.List;
@@ -1607,4 +1608,82 @@
             return null;
         }
     }
+
+    /**
+     * 鍘熷瓙鍔�
+     * @param key 閿�
+     * @param num 鏁伴噺
+     */
+    public Long increment(String key,long num) {
+        try {
+            return redisTemplate.opsForValue().increment(key, num);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * 鍘熷瓙鍔�
+     * @param key 閿�
+     * @param num 鏁伴噺
+     * @param db 鏁版嵁搴�
+     */
+    public Long increment(String key,long num,int db) {
+        try {
+            RedisTemplate redisTemplate = redisManager.getRedisTemplate(db);
+            return redisTemplate.opsForValue().increment(key, num);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * 鍘熷瓙鍑�
+     * @param key 閿�
+     * @param num 鏁伴噺
+     */
+    public Long decrement(String key,long num) {
+        try {
+            return redisTemplate.opsForValue().decrement(key, num);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * 鍘熷瓙鍑�
+     * @param key 閿�
+     * @param num 鏁伴噺
+     * @param db 鏁版嵁搴�
+     */
+    public Long decrement(String key,long num,int db) {
+        try {
+            RedisTemplate redisTemplate = redisManager.getRedisTemplate(db);
+            return redisTemplate.opsForValue().decrement(key, num);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+
+    /**
+     * 鑾峰彇绾㈤攣
+     * @param key  閿乲ey
+     * @param db 鏁版嵁搴撶紪鍙�
+     */
+    public RLock getRLock(String key,int db) {
+        RLock lock = null;
+        try {
+            RedissonClient redissonClient = RedisManager.redissonTemplateMap.get(db+"");
+            lock = redissonClient.getLock(key);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return lock;
+    }
+
 }

--
Gitblit v1.8.0