Commit 85994b69205ba31971ea30d201c19a162fe7937a
1 parent
c9482452
🐛 修复 Spring Cache Redis 单冒号,而不是双 :: 冒号,避免 Redis Desktop Manager 多余空格
Showing
1 changed file
with
10 additions
and
4 deletions
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; |
| 15 | 15 | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| 16 | 16 | import org.springframework.data.redis.core.RedisTemplate; |
| 17 | 17 | import org.springframework.data.redis.serializer.RedisSerializationContext; |
| 18 | +import org.springframework.util.StringUtils; | |
| 18 | 19 | |
| 19 | 20 | import java.util.Objects; |
| 20 | 21 | |
| ... | ... | @@ -39,7 +40,15 @@ public class YudaoCacheAutoConfiguration { |
| 39 | 40 | RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig(); |
| 40 | 41 | // 设置使用 : 单冒号,而不是双 :: 冒号,避免 Redis Desktop Manager 多余空格 |
| 41 | 42 | // 详细可见 https://blog.csdn.net/chuixue24/article/details/103928965 博客 |
| 42 | - config = config.computePrefixWith(cacheName -> cacheName + StrUtil.COLON); | |
| 43 | + // 再次修复单冒号,而不是双 :: 冒号问题,Issues 详情:https://gitee.com/zhijiantianya/yudao-cloud/issues/I86VY2 | |
| 44 | + config = config.computePrefixWith(cacheName -> { | |
| 45 | + String keyPrefix = cacheProperties.getRedis().getKeyPrefix(); | |
| 46 | + if (StringUtils.hasText(keyPrefix)) { | |
| 47 | + keyPrefix = keyPrefix.lastIndexOf(StrUtil.COLON) == -1 ? keyPrefix + StrUtil.COLON : keyPrefix; | |
| 48 | + return keyPrefix + cacheName + StrUtil.COLON; | |
| 49 | + } | |
| 50 | + return cacheName + StrUtil.COLON; | |
| 51 | + }); | |
| 43 | 52 | // 设置使用 JSON 序列化方式 |
| 44 | 53 | config = config.serializeValuesWith( |
| 45 | 54 | RedisSerializationContext.SerializationPair.fromSerializer(buildRedisSerializer())); |
| ... | ... | @@ -49,9 +58,6 @@ public class YudaoCacheAutoConfiguration { |
| 49 | 58 | if (redisProperties.getTimeToLive() != null) { |
| 50 | 59 | config = config.entryTtl(redisProperties.getTimeToLive()); |
| 51 | 60 | } |
| 52 | - if (redisProperties.getKeyPrefix() != null) { | |
| 53 | - config = config.prefixCacheNameWith(redisProperties.getKeyPrefix()); | |
| 54 | - } | |
| 55 | 61 | if (!redisProperties.isCacheNullValues()) { |
| 56 | 62 | config = config.disableCachingNullValues(); |
| 57 | 63 | } | ... | ... |