From b5391c3ed253cc5d85476179b0bcd0c148bd2067 Mon Sep 17 00:00:00 2001 From: "862412451@qq.com" Date: Tue, 5 Dec 2023 14:40:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dspring=20cache=20redis?= =?UTF-8?q?=20=E5=8D=95=E5=86=92=E5=8F=B7=EF=BC=8C=E8=80=8C=E4=B8=8D?= =?UTF-8?q?=E6=98=AF=E5=8F=8C=20::=20=E5=86=92=E5=8F=B7=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=85=8D=20Redis=20Desktop=20Manager=20=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=A9=BA=E6=A0=BC=E3=80=82issues=E8=AF=A6=E6=83=85=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=EF=BC=9A=20https://gitee.com/zhijiantianya/yudao-clou?= =?UTF-8?q?d/issues/I86VY2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../redis/config/YudaoCacheAutoConfiguration.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java index 2797e2117..9e84c4a49 100644 --- a/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-redis/src/main/java/cn/iocoder/yudao/framework/redis/config/YudaoCacheAutoConfiguration.java @@ -15,6 +15,7 @@ import org.springframework.data.redis.cache.RedisCacheWriter; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.util.StringUtils; import java.util.Objects; @@ -39,7 +40,15 @@ public class YudaoCacheAutoConfiguration { RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); // 设置使用 : 单冒号,而不是双 :: 冒号,避免 Redis Desktop Manager 多余空格 // 详细可见 https://blog.csdn.net/chuixue24/article/details/103928965 博客 - config = config.computePrefixWith(cacheName -> cacheName + StrUtil.COLON); + // 再次修复单冒号,而不是双 :: 冒号问题,Issues 详情:https://gitee.com/zhijiantianya/yudao-cloud/issues/I86VY2 + config = config.computePrefixWith(cacheName -> { + String keyPrefix = cacheProperties.getRedis().getKeyPrefix(); + if (StringUtils.hasText(keyPrefix)) { + keyPrefix = keyPrefix.lastIndexOf(StrUtil.COLON) == -1 ? keyPrefix + StrUtil.COLON : keyPrefix; + return keyPrefix + cacheName + StrUtil.COLON; + } + return cacheName + StrUtil.COLON; + }); // 设置使用 JSON 序列化方式 config = config.serializeValuesWith( RedisSerializationContext.SerializationPair.fromSerializer(buildRedisSerializer())); @@ -49,9 +58,6 @@ public class YudaoCacheAutoConfiguration { if (redisProperties.getTimeToLive() != null) { config = config.entryTtl(redisProperties.getTimeToLive()); } - if (redisProperties.getKeyPrefix() != null) { - config = config.prefixCacheNameWith(redisProperties.getKeyPrefix()); - } if (!redisProperties.isCacheNullValues()) { config = config.disableCachingNullValues(); }