mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-12-07 21:00:10 +08:00
feat(cache/redisson): 新增 RedisUtils#getOrDefault 方法
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package top.continew.starter.cache.redisson.util;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import org.redisson.api.*;
|
||||
import org.redisson.api.options.KeysScanOptions;
|
||||
@@ -138,6 +139,18 @@ public class RedisUtils {
|
||||
return bucket.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询指定缓存,若不存在则返回默认值
|
||||
*
|
||||
* @param key 键
|
||||
* @param defaultValue 默认值
|
||||
* @return 值
|
||||
* @since 2.15.0
|
||||
*/
|
||||
public static <T> T getOrDefault(String key, T defaultValue) {
|
||||
return ObjectUtil.defaultIfNull(get(key), defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置缓存(List 集合)
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user