mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
redisCache 工具类中新增 批量添加list集合方法
This commit is contained in:
@@ -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 <T> long batchSetCacheList(final Map<String, List<T>> map, long timeout, TimeUnit unit) {
|
||||
long totalCount = 0;
|
||||
|
||||
for (Map.Entry<String, List<T>> 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对象
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user