diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisCacheStore.java b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisCacheStore.java index d4b551f..f96a777 100644 --- a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisCacheStore.java +++ b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisCacheStore.java @@ -44,7 +44,7 @@ public abstract class RedisCacheStore implements CacheStore { * @return 返回 Key 前缀. */ protected String getKeyString(CacheKey cacheKey) { - return getKeyPrefix() + cacheKey.join(RedisUtils.KEY_SEPARATOR); + return RedisUtils.toRedisCacheKey(getKeyPrefix(), cacheKey); } /** diff --git a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisUtils.java b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisUtils.java index c84dc3a..cf7e06b 100644 --- a/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisUtils.java +++ b/ContentGrabbingJi-CacheStore-redis/src/main/java/net/lamgc/cgj/bot/cache/redis/RedisUtils.java @@ -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); + } + }