From 4feb321e6fa88e86991da3610b2bdfcf5a2d87a7 Mon Sep 17 00:00:00 2001
From: wujianwei <wjw@11.com>
Date: 星期三, 14 一月 2026 16:50:44 +0800
Subject: [PATCH] 新增字段

---
 common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java |  137 ++++++++++++++++++++++++++++++++-------------
 1 files changed, 96 insertions(+), 41 deletions(-)

diff --git a/common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java b/common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
index 44e80d8..2063dd5 100644
--- a/common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
+++ b/common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
@@ -6,7 +6,10 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
+
+import com.ruoyi.common.utils.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.BoundSetOperations;
 import org.springframework.data.redis.core.HashOperations;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -23,16 +26,21 @@
 public class RedisCache
 {
     @Autowired
-    public RedisTemplate redisTemplate;
+    private RedisTemplate redisTemplate;
 
+    @Value("${spring.redis.keyprefix}")
+    private String keyPrefix;
     /**
      * 缂撳瓨鍩烘湰鐨勫璞★紝Integer銆丼tring銆佸疄浣撶被绛�
      *
      * @param key 缂撳瓨鐨勯敭鍊�
      * @param value 缂撳瓨鐨勫��
      */
-    public <T> void setCacheObject(final String key, final T value)
+    public <T> void setCacheObject( String key, final T value)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         redisTemplate.opsForValue().set(key, value);
     }
 
@@ -44,8 +52,11 @@
      * @param timeout 鏃堕棿
      * @param timeUnit 鏃堕棿棰楃矑搴�
      */
-    public <T> void setCacheObject(final String key, final T value, final Integer timeout, final TimeUnit timeUnit)
+    public <T> void setCacheObject( String key, final T value, final Integer timeout, final TimeUnit timeUnit)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
     }
 
@@ -56,8 +67,11 @@
      * @param timeout 瓒呮椂鏃堕棿
      * @return true=璁剧疆鎴愬姛锛沠alse=璁剧疆澶辫触
      */
-    public boolean expire(final String key, final long timeout)
+    public boolean expire( String key, final long timeout)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         return expire(key, timeout, TimeUnit.SECONDS);
     }
 
@@ -69,31 +83,12 @@
      * @param unit 鏃堕棿鍗曚綅
      * @return true=璁剧疆鎴愬姛锛沠alse=璁剧疆澶辫触
      */
-    public boolean expire(final String key, final long timeout, final TimeUnit unit)
+    public boolean expire( String key, final long timeout, final TimeUnit unit)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         return redisTemplate.expire(key, timeout, unit);
-    }
-
-    /**
-     * 鑾峰彇鏈夋晥鏃堕棿
-     *
-     * @param key Redis閿�
-     * @return 鏈夋晥鏃堕棿
-     */
-    public long getExpire(final String key)
-    {
-        return redisTemplate.getExpire(key);
-    }
-
-    /**
-     * 鍒ゆ柇 key鏄惁瀛樺湪
-     *
-     * @param key 閿�
-     * @return true 瀛樺湪 false涓嶅瓨鍦�
-     */
-    public Boolean hasKey(String key)
-    {
-        return redisTemplate.hasKey(key);
     }
 
     /**
@@ -102,8 +97,11 @@
      * @param key 缂撳瓨閿��
      * @return 缂撳瓨閿�煎搴旂殑鏁版嵁
      */
-    public <T> T getCacheObject(final String key)
+    public <T> T getCacheObject(String key)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         ValueOperations<String, T> operation = redisTemplate.opsForValue();
         return operation.get(key);
     }
@@ -113,21 +111,37 @@
      *
      * @param key
      */
-    public boolean deleteObject(final String key)
+    public boolean deleteObject( String key)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         return redisTemplate.delete(key);
     }
-
     /**
      * 鍒犻櫎闆嗗悎瀵硅薄
      *
      * @param collection 澶氫釜瀵硅薄
      * @return
      */
-    public boolean deleteObject(final Collection collection)
+    public long deleteObject(final Collection collection)
     {
-        return redisTemplate.delete(collection) > 0;
+        return redisTemplate.delete(collection);
     }
+    /**
+     * 鍒犻櫎鍗曚釜瀵硅薄
+     *
+     * @param key
+     */
+    public Long deleteMapValue( String key,String hashKey)
+    {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
+        return redisTemplate.opsForHash().delete(key,hashKey);
+    }
+
+
 
     /**
      * 缂撳瓨List鏁版嵁
@@ -136,8 +150,11 @@
      * @param dataList 寰呯紦瀛樼殑List鏁版嵁
      * @return 缂撳瓨鐨勫璞�
      */
-    public <T> long setCacheList(final String key, final List<T> dataList)
+    public <T> long setCacheList( String key, final List<T> dataList)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
         return count == null ? 0 : count;
     }
@@ -148,8 +165,11 @@
      * @param key 缂撳瓨鐨勯敭鍊�
      * @return 缂撳瓨閿�煎搴旂殑鏁版嵁
      */
-    public <T> List<T> getCacheList(final String key)
+    public <T> List<T> getCacheList( String key)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         return redisTemplate.opsForList().range(key, 0, -1);
     }
 
@@ -160,8 +180,11 @@
      * @param dataSet 缂撳瓨鐨勬暟鎹�
      * @return 缂撳瓨鏁版嵁鐨勫璞�
      */
-    public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet)
+    public <T> BoundSetOperations<String, T> setCacheSet( String key, final Set<T> dataSet)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
         Iterator<T> it = dataSet.iterator();
         while (it.hasNext())
@@ -177,8 +200,11 @@
      * @param key
      * @return
      */
-    public <T> Set<T> getCacheSet(final String key)
+    public <T> Set<T> getCacheSet( String key)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         return redisTemplate.opsForSet().members(key);
     }
 
@@ -188,8 +214,11 @@
      * @param key
      * @param dataMap
      */
-    public <T> void setCacheMap(final String key, final Map<String, T> dataMap)
+    public <T> void setCacheMap( String key, final Map<String, T> dataMap)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         if (dataMap != null) {
             redisTemplate.opsForHash().putAll(key, dataMap);
         }
@@ -201,8 +230,11 @@
      * @param key
      * @return
      */
-    public <T> Map<String, T> getCacheMap(final String key)
+    public <T> Map<String, T> getCacheMap( String key)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         return redisTemplate.opsForHash().entries(key);
     }
 
@@ -213,8 +245,11 @@
      * @param hKey Hash閿�
      * @param value 鍊�
      */
-    public <T> void setCacheMapValue(final String key, final String hKey, final T value)
+    public <T> void setCacheMapValue( String key, final String hKey, final T value)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         redisTemplate.opsForHash().put(key, hKey, value);
     }
 
@@ -225,8 +260,11 @@
      * @param hKey Hash閿�
      * @return Hash涓殑瀵硅薄
      */
-    public <T> T getCacheMapValue(final String key, final String hKey)
+    public <T> T getCacheMapValue( String key, final String hKey)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
         return opsForHash.get(key, hKey);
     }
@@ -238,8 +276,11 @@
      * @param hKeys Hash閿泦鍚�
      * @return Hash瀵硅薄闆嗗悎
      */
-    public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys)
+    public <T> List<T> getMultiCacheMapValue( String key, final Collection<Object> hKeys)
     {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
         return redisTemplate.opsForHash().multiGet(key, hKeys);
     }
 
@@ -265,4 +306,18 @@
     {
         return redisTemplate.keys(pattern);
     }
+
+    /**
+     * 鍒ゆ柇 key鏄惁瀛樺湪
+     *
+     * @param key 閿�
+     * @return true 瀛樺湪 false涓嶅瓨鍦�
+     */
+    public Boolean hasKey(String key)
+    {
+        if(StringUtils.isNotNull(keyPrefix)){
+            key = keyPrefix + ":"+key;
+        }
+        return redisTemplate.hasKey(key);
+    }
 }

--
Gitblit v1.8.0