mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-11 06:57:14 +08:00
feat(cache/redisson): RedisUtils 新增递增、递减方法
This commit is contained in:
@@ -74,6 +74,6 @@ public class JustAuthStateCacheRedisImpl implements AuthStateCache {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean containsKey(String key) {
|
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.time.Duration;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redis 工具类
|
* Redis 工具类
|
||||||
@@ -92,6 +91,28 @@ public class RedisUtils {
|
|||||||
CLIENT.getKeys().deleteByPattern(pattern);
|
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 键
|
* @param key 键
|
||||||
* @return true:存在;false:不存在
|
* @return true:存在;false:不存在
|
||||||
*/
|
*/
|
||||||
public static boolean hasKey(String key) {
|
public static boolean exists(String key) {
|
||||||
RKeys keys = CLIENT.getKeys();
|
return CLIENT.getKeys().countExists(key) > 0;
|
||||||
return keys.countExists(key) > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -142,8 +162,7 @@ public class RedisUtils {
|
|||||||
* @return 缓存列表
|
* @return 缓存列表
|
||||||
*/
|
*/
|
||||||
public static Collection<String> keys(String pattern) {
|
public static Collection<String> keys(String pattern) {
|
||||||
Stream<String> stream = CLIENT.getKeys().getKeysStreamByPattern(pattern);
|
return CLIENT.getKeys().getKeysStreamByPattern(pattern).toList();
|
||||||
return stream.toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -36,7 +36,7 @@ public class BehaviorCaptchaCacheServiceImpl implements CaptchaCacheService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exists(String key) {
|
public boolean exists(String key) {
|
||||||
return RedisUtils.hasKey(key);
|
return RedisUtils.exists(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user