From 92fd0a8ab2c0250981aceb006a86c1e911719970 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Sun, 23 Jun 2024 10:09:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(cache/redisson):=20=E6=96=B0=E5=A2=9E=20Li?= =?UTF-8?q?st=20=E7=BC=93=E5=AD=98=E6=93=8D=E4=BD=9C=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cache/redisson/util/RedisUtils.java | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) 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 c814abc0..73ebd973 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 @@ -22,6 +22,7 @@ import top.continew.starter.core.constant.StringConstants; import java.time.Duration; import java.util.Collection; +import java.util.List; /** * Redis 工具类 @@ -54,11 +55,7 @@ public class RedisUtils { * @param duration 过期时间 */ public static void set(String key, T value, Duration duration) { - RBatch batch = CLIENT.createBatch(); - RBucketAsync bucket = batch.getBucket(key); - bucket.setAsync(value); - bucket.expireAsync(duration); - batch.execute(); + CLIENT.getBucket(key).set(value, duration); } /** @@ -72,6 +69,46 @@ public class RedisUtils { return bucket.get(); } + /** + * 设置缓存(List 集合) + * + * @param key 键 + * @param value 值 + * @since 2.1.1 + */ + public static void setList(String key, List value) { + RList list = CLIENT.getList(key); + list.addAll(value); + } + + /** + * 设置缓存(List 集合) + * + * @param key 键 + * @param value 值 + * @param duration 过期时间 + * @since 2.1.1 + */ + public static void setList(String key, List value, Duration duration) { + RBatch batch = CLIENT.createBatch(); + RListAsync list = batch.getList(key); + list.addAllAsync(value); + list.expireAsync(duration); + batch.execute(); + } + + /** + * 查询指定缓存(List 集合) + * + * @param key 键 + * @return 值 + * @since 2.1.1 + */ + public static List getList(String key) { + RList list = CLIENT.getList(key); + return list.readAll(); + } + /** * 删除缓存 * @@ -113,17 +150,6 @@ public class RedisUtils { return CLIENT.getAtomicLong(key).decrementAndGet(); } - /** - * 设置缓存过期时间 - * - * @param key 键 - * @param timeout 过期时间(单位:秒) - * @return true:设置成功;false:设置失败 - */ - public static boolean expire(String key, long timeout) { - return expire(key, Duration.ofSeconds(timeout)); - } - /** * 设置缓存过期时间 *