Skip to content

Commit a512b29

Browse files
committed
feat(cache/redisson): 新增 RedisUtils#getOrDefault 方法
1 parent 0798424 commit a512b29

File tree

1 file changed

+13
-0
lines changed
  • continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util

1 file changed

+13
-0
lines changed

continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package top.continew.starter.cache.redisson.util;
1818

1919
import cn.hutool.core.util.ArrayUtil;
20+
import cn.hutool.core.util.ObjectUtil;
2021
import cn.hutool.extra.spring.SpringUtil;
2122
import org.redisson.api.*;
2223
import org.redisson.api.options.KeysScanOptions;
@@ -138,6 +139,18 @@ public static <T> T get(String key) {
138139
return bucket.get();
139140
}
140141

142+
/**
143+
* 查询指定缓存,若不存在则返回默认值
144+
*
145+
* @param key 键
146+
* @param defaultValue 默认值
147+
* @return 值
148+
* @since 2.15.0
149+
*/
150+
public static <T> T getOrDefault(String key, T defaultValue) {
151+
return ObjectUtil.defaultIfNull(get(key), defaultValue);
152+
}
153+
141154
/**
142155
* 设置缓存(List 集合)
143156
*

0 commit comments

Comments
 (0)