From c24d16a37523a49080392610357872ce580cbc38 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期一, 26 十月 2026 14:03:33 +0800
Subject: [PATCH] 代码提交

---
 ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 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 8955e98..605ebc8 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
@@ -30,6 +30,10 @@
         redisTemplate.opsForValue().set(key, value);
     }
 
+    public <T> void setCacheList(final String key, final List<T> values) {
+        redisTemplate.opsForList().rightPushAll(key, values);
+    }
+
     /**
      * 缂撳瓨鍩烘湰鐨勫璞★紝Integer銆丼tring銆佸疄浣撶被绛�
      *
@@ -40,6 +44,23 @@
      */
     public <T> void setCacheObject(final String key, final T value, final long timeout, final TimeUnit timeUnit) {
         redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
+    }
+
+    /**
+     * 浠呭綋 key 涓嶅瓨鍦ㄦ椂鍐欏叆锛圫ETNX 璇箟锛夛紝鐢ㄤ簬<b>骞傜瓑/闃查噸澶嶆彁浜�</b>
+     * <p>
+     * 2026-10-21 鏂板锛氶棶鍗锋彁浜ゆ帴鍙o紙{@code /smartor/subtaskAnswer/saveQuestionAnswer}锛夋槸
+     * {@code @Async} 寮傛澶勭悊锛屾偅鑰呯閲嶅鐐瑰嚮/缃戠粶閲嶈瘯浼氬苟鍙戝啓澶氫唤鏄庣粏锛岄渶瑕佺敤鍘熷瓙鍗犱綅鎸℃帀銆�
+     *
+     * @param key      Redis 閿�
+     * @param value    鍐欏叆鐨勫��
+     * @param timeout  杩囨湡鏃堕棿
+     * @param timeUnit 鏃堕棿棰楃矑搴�
+     * @return {@code true} = 鍗犱綅鎴愬姛锛堟湰娆″簲缁х画澶勭悊锛夛紱{@code false} = 宸插瓨鍦紙閲嶅璇锋眰锛屽簲蹇界暐锛�
+     */
+    public <T> boolean setCacheObjectIfAbsent(final String key, final T value, final long timeout, final TimeUnit timeUnit) {
+        Boolean ok = redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
+        return Boolean.TRUE.equals(ok);
     }
 
     /**
@@ -299,4 +320,27 @@
     public Collection<String> keys(final String pattern) {
         return redisTemplate.keys(pattern);
     }
+
+    /**
+     * 鑾峰彇褰撳墠key鍊肩殑鏁伴噺
+     * @param key
+     * @return
+     */
+    public Long getListSize(String key) {
+        // 妫�鏌� key 绫诲瀷
+        DataType keyType = redisTemplate.type(key);
+
+        // 濡傛灉 key 涓嶅瓨鍦紝杩斿洖 0
+        if (keyType == DataType.NONE) {
+            return 0L;
+        }
+
+        // 濡傛灉涓嶆槸 List 绫诲瀷锛屽垹闄ゅ畠骞惰繑鍥� 0锛堥槻姝� WRONGTYPE 閿欒锛�
+        if (keyType != DataType.LIST) {
+            redisTemplate.delete(key);
+            return 0L;
+        }
+
+        return redisTemplate.opsForList().size(key);
+    }
 }

--
Gitblit v1.9.3