From 55f5271f893a25a7be671b24938e49976936a67b Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 29 九月 2025 18:30:00 +0800
Subject: [PATCH] 新增Orgid

---
 ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
index 5eecedc..79785fd 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
@@ -5,6 +5,7 @@
 import java.util.stream.Collectors;
 
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.connection.DataType;
 import org.springframework.data.redis.core.*;
 import org.springframework.stereotype.Component;
 
@@ -27,6 +28,10 @@
      */
     public <T> void setCacheObject(final String key, final T value) {
         redisTemplate.opsForValue().set(key, value);
+    }
+
+    public <T> void setCacheList(final String key, final List<T> values) {
+        redisTemplate.opsForList().rightPushAll(key, values);
     }
 
     /**
@@ -141,21 +146,23 @@
     /**
      * 缂撳瓨List鏁版嵁
      *
-     * @param cacheKey      缂撳瓨鐨勯敭鍊�
-     * @param list 寰呯紦瀛樼殑List鏁版嵁(杩欓噷濡傛灉鏂板鐨勮瘽锛屾槸寰�澶撮儴鏂板)骞跺幓閲�
+     * @param cacheKey 缂撳瓨鐨勯敭鍊�
+     * @param list     寰呯紦瀛樼殑List鏁版嵁(杩欓噷濡傛灉鏂板鐨勮瘽锛屾槸寰�澶撮儴鏂板)骞跺幓閲�
      * @return 缂撳瓨鐨勫璞�
      */
     public void setCacheListLeftAndDistinct(String cacheKey, List<String> list) {
-        // 鑾峰彇 ListOperations 瀵硅薄锛岀敤浜庢搷浣� Redis List
-        ListOperations<String, String> listOps = redisTemplate.opsForList();
+        // 妫�鏌� key 绫诲瀷
+        DataType keyType = redisTemplate.type(cacheKey);
+        if (keyType != DataType.NONE && keyType != DataType.LIST) {
+            // 濡傛灉宸茬粡瀛樺湪浣嗕笉鏄� list 绫诲瀷锛屽垹闄ゅ畠锛堟垨鐩存帴鎶涘紓甯镐篃鍙級
+            redisTemplate.delete(cacheKey);
+        }
 
-        // 鑾峰彇鐜版湁鐨� cache-0 鍒楄〃涓殑鎵�鏈夊��
+        ListOperations<String, String> listOps = redisTemplate.opsForList();
         List<String> existingValues = listOps.range(cacheKey, 0, -1);
 
-        // 杩囨护鍑轰笉鍦� Redis 鍒楄〃涓殑鍊�
         List<String> newValues = list.stream().filter(value -> !existingValues.contains(value)).collect(Collectors.toList());
 
-        // 灏嗘柊鐨勫�兼坊鍔犲埌 Redis 鍒楄〃鐨勫乏渚�
         if (!newValues.isEmpty()) {
             listOps.leftPushAll(cacheKey, newValues);
         }
@@ -296,4 +303,13 @@
     public Collection<String> keys(final String pattern) {
         return redisTemplate.keys(pattern);
     }
+
+    /**
+     * 鑾峰彇褰撳墠key鍊肩殑鏁伴噺
+     * @param key
+     * @return
+     */
+    public Long getListSize(String key) {
+        return redisTemplate.opsForList().size(key);
+    }
 }

--
Gitblit v1.9.3