diff --git a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java index b5f3d873..719b6932 100644 --- a/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java +++ b/continew-starter-cache/continew-starter-cache-redisson/src/main/java/top/continew/starter/cache/redisson/util/RedisUtils.java @@ -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 getOrDefault(String key, T defaultValue) { + return ObjectUtil.defaultIfNull(get(key), defaultValue); + } + /** * 设置缓存(List 集合) *