From 596605b27b046fa0488b113b1c3d87c60277e4ec Mon Sep 17 00:00:00 2001 From: Charles7c Date: Mon, 13 May 2024 21:57:42 +0800 Subject: [PATCH] =?UTF-8?q?feat(cache/redisson):=20RedisUtils=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E9=80=92=E5=A2=9E=E3=80=81=E9=80=92=E5=87=8F=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/JustAuthStateCacheRedisImpl.java | 2 +- .../cache/redisson/util/RedisUtils.java | 31 +++++++++++++++---- .../BehaviorCaptchaCacheServiceImpl.java | 2 +- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/core/JustAuthStateCacheRedisImpl.java b/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/core/JustAuthStateCacheRedisImpl.java index bda93263..64ef5742 100644 --- a/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/core/JustAuthStateCacheRedisImpl.java +++ b/continew-starter-auth/continew-starter-auth-justauth/src/main/java/top/continew/starter/auth/justauth/core/JustAuthStateCacheRedisImpl.java @@ -74,6 +74,6 @@ public class JustAuthStateCacheRedisImpl implements AuthStateCache { */ @Override public boolean containsKey(String key) { - return RedisUtils.hasKey(RedisUtils.formatKey(KEY_PREFIX, key)); + return RedisUtils.exists(RedisUtils.formatKey(KEY_PREFIX, key)); } } \ No newline at end of file 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 d367bc30..c814abc0 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,7 +22,6 @@ import top.continew.starter.core.constant.StringConstants; import java.time.Duration; import java.util.Collection; -import java.util.stream.Stream; /** * Redis 工具类 @@ -92,6 +91,28 @@ public class RedisUtils { CLIENT.getKeys().deleteByPattern(pattern); } + /** + * 递增 1 + * + * @param key 键 + * @return 当前值 + * @since 2.0.1 + */ + public static long incr(String key) { + return CLIENT.getAtomicLong(key).incrementAndGet(); + } + + /** + * 递减 1 + * + * @param key 键 + * @return 当前值 + * @since 2.0.1 + */ + public static long decr(String key) { + return CLIENT.getAtomicLong(key).decrementAndGet(); + } + /** * 设置缓存过期时间 * @@ -130,9 +151,8 @@ public class RedisUtils { * @param key 键 * @return true:存在;false:不存在 */ - public static boolean hasKey(String key) { - RKeys keys = CLIENT.getKeys(); - return keys.countExists(key) > 0; + public static boolean exists(String key) { + return CLIENT.getKeys().countExists(key) > 0; } /** @@ -142,8 +162,7 @@ public class RedisUtils { * @return 缓存列表 */ public static Collection keys(String pattern) { - Stream stream = CLIENT.getKeys().getKeysStreamByPattern(pattern); - return stream.toList(); + return CLIENT.getKeys().getKeysStreamByPattern(pattern).toList(); } /** diff --git a/continew-starter-captcha/continew-starter-captcha-behavior/src/main/java/top/continew/starter/captcha/behavior/autoconfigure/cache/BehaviorCaptchaCacheServiceImpl.java b/continew-starter-captcha/continew-starter-captcha-behavior/src/main/java/top/continew/starter/captcha/behavior/autoconfigure/cache/BehaviorCaptchaCacheServiceImpl.java index cecacef3..f61107c1 100644 --- a/continew-starter-captcha/continew-starter-captcha-behavior/src/main/java/top/continew/starter/captcha/behavior/autoconfigure/cache/BehaviorCaptchaCacheServiceImpl.java +++ b/continew-starter-captcha/continew-starter-captcha-behavior/src/main/java/top/continew/starter/captcha/behavior/autoconfigure/cache/BehaviorCaptchaCacheServiceImpl.java @@ -36,7 +36,7 @@ public class BehaviorCaptchaCacheServiceImpl implements CaptchaCacheService { @Override public boolean exists(String key) { - return RedisUtils.hasKey(key); + return RedisUtils.exists(key); } @Override