diff --git a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java index b2987c5d7..2af1cd5d0 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java +++ b/jsowell-common/src/main/java/com/jsowell/common/core/redis/RedisCache.java @@ -1,6 +1,7 @@ package com.jsowell.common.core.redis; import com.jsowell.common.util.StringUtils; +import org.apache.poi.ss.formula.functions.T; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -209,6 +210,33 @@ public class RedisCache { return count == null ? 0 : count; } + /** + * 批量存储 List 集合到 Redis,并设置缓存超时时间 + * + * @param map 其中 map 的 key 为缓存键值,value 为 List 集合 + * @param timeout 缓存超时时间 + * @param unit 超时时间的单位(如 TimeUnit.SECONDS、TimeUnit.MINUTES) + * @return 存储成功的元素总数 + */ + public long batchSetCacheList(final Map> map, long timeout, TimeUnit unit) { + long totalCount = 0; + + for (Map.Entry> entry : map.entrySet()) { + String key = entry.getKey(); + List dataList = entry.getValue(); + + if (dataList != null && !dataList.isEmpty()) { + Long count = redisTemplate.opsForList().rightPushAll(key, dataList); + totalCount += (count != null ? count : 0); + + // 设置缓存超时时间 + redisTemplate.expire(key, timeout, unit); + } + } + + return totalCount; + } + /** * 获得缓存的list对象 *