From 8676f9b5912914f2bc1025d7695e2b11136bad20 Mon Sep 17 00:00:00 2001 From: KAI <1373639299@qq.com> Date: Wed, 23 Jul 2025 13:49:38 +0000 Subject: [PATCH] =?UTF-8?q?feat(cache/redisson):=20RedisUtils=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20Hash=20=E5=B8=B8=E7=94=A8=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=88hSet/hGet/hGetAll/hExists/hDel?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cache/redisson/util/RedisUtils.java | 65 +++++++++++++++++++ 1 file changed, 65 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 a3ab2479..28b4927a 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 @@ -25,6 +25,7 @@ import top.continew.starter.core.constant.StringConstants; import java.time.Duration; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -534,4 +535,68 @@ public class RedisUtils { public static String formatKey(String... subKeys) { return String.join(StringConstants.COLON, ArrayUtil.removeBlank(subKeys)); } + + /** + * 设置 Hash 中指定字段的值 + * + * @param key Hash 键 + * @param field 字段 + * @param value 值 + * @since 2.13.4 + */ + public static void hSet(String key, String field, T value) { + RMap map = CLIENT.getMap(key); + map.put(field, value); + } + + /** + * 获取 Hash 中指定字段的值 + * + * @param key Hash 键 + * @param field 字段 + * @return 值 + * @since 2.13.4 + */ + public static T hGet(String key, String field) { + RMap map = CLIENT.getMap(key); + return map.get(field); + } + + /** + * 获取整个 Hash 的所有字段值 + * + * @param key Hash 键 + * @return Map + * @since 2.13.4 + */ + public static Map hGetAll(String key) { + RMap map = CLIENT.getMap(key); + return map.readAllMap(); + } + + /** + * 判断 Hash 中是否存在指定字段 + * + * @param key Hash 键 + * @param field 字段 + * @return true:存在;false:不存在 + * @since 2.13.4 + */ + public static boolean hExists(String key, String field) { + RMap map = CLIENT.getMap(key); + return map.containsKey(field); + } + + /** + * 删除 Hash 中指定字段 + * + * @param key Hash 键 + * @param fields 字段数组 + * @return 删除成功的字段数量 + * @since 2.13.4 + */ + public static long hDel(String key, String... fields) { + RMap map = CLIENT.getMap(key); + return map.fastRemove(fields); + } }