From a512b29082be98179f3aab009f40765af4be7b49 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Wed, 3 Dec 2025 20:27:37 +0800 Subject: [PATCH] =?UTF-8?q?feat(cache/redisson):=20=E6=96=B0=E5=A2=9E=20Re?= =?UTF-8?q?disUtils#getOrDefault=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../starter/cache/redisson/util/RedisUtils.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 集合) *