mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-08 16:57:09 +08:00
feat(cache/redisson): RedisUtils 新增递增、递减方法
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
@@ -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<String> keys(String pattern) {
|
||||
Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(pattern);
|
||||
return stream.toList();
|
||||
return CLIENT.getKeys().getKeysStreamByPattern(pattern).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -36,7 +36,7 @@ public class BehaviorCaptchaCacheServiceImpl implements CaptchaCacheService {
|
||||
|
||||
@Override
|
||||
public boolean exists(String key) {
|
||||
return RedisUtils.hasKey(key);
|
||||
return RedisUtils.exists(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user