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