mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-29 14:17:33 +00:00
[Change] CacheStore-Redis 迁移工具方法到 RedisUtils;
[Change] RedisCacheStore, RedisUtils 迁移 'getKeyString(CacheKey)' 方法的具体实现到 RedisUtils (方法: 'toRedisCacheKey(String, CacheKey)'); [Add] RedisUtils 添加 CACHE_KEY_ALL 以构建对 CacheStore 所有 Key 的匹配规则;
This commit is contained in:
parent
a6fc04c07e
commit
8108379f96
@ -44,7 +44,7 @@ public abstract class RedisCacheStore<V> implements CacheStore<V> {
|
||||
* @return 返回 Key 前缀.
|
||||
*/
|
||||
protected String getKeyString(CacheKey cacheKey) {
|
||||
return getKeyPrefix() + cacheKey.join(RedisUtils.KEY_SEPARATOR);
|
||||
return RedisUtils.toRedisCacheKey(getKeyPrefix(), cacheKey);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package net.lamgc.cgj.bot.cache.redis;
|
||||
|
||||
import net.lamgc.cgj.bot.cache.CacheKey;
|
||||
|
||||
/**
|
||||
* @author LamGC
|
||||
*/
|
||||
@ -33,10 +35,15 @@ public class RedisUtils {
|
||||
public final static int RETURN_CODE_FAILED = 0;
|
||||
|
||||
/**
|
||||
* Key匹配规则 - 所有Key
|
||||
* Key 匹配规则 - 所有 Key
|
||||
*/
|
||||
public final static String KEY_PATTERN_ALL = "*";
|
||||
|
||||
/**
|
||||
* 特殊缓存键 - 所有 Key.
|
||||
*/
|
||||
public final static CacheKey CACHE_KEY_ALL = new CacheKey("*");
|
||||
|
||||
/**
|
||||
* Key 分隔符
|
||||
*/
|
||||
@ -51,4 +58,15 @@ public class RedisUtils {
|
||||
return "OK".equalsIgnoreCase(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 {@link CacheKey} 转换为 Redis 的标准 key 格式.
|
||||
* @param keyPrefix Key 前缀.
|
||||
* @param cacheKey 缓存键对象.
|
||||
* @return 返回格式化后的 Key.
|
||||
*/
|
||||
public static String toRedisCacheKey(String keyPrefix, CacheKey cacheKey) {
|
||||
return (keyPrefix.endsWith(KEY_SEPARATOR) ? keyPrefix : (keyPrefix + KEY_SEPARATOR)) +
|
||||
cacheKey.join(RedisUtils.KEY_SEPARATOR);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user