我有2个jedis缓存:
-
localhost:6379
-
cache.servermachine.com:6380,password=abcdef
其中一个redis实例在本地托管,另一个在具有密码的安全机器上托管 . 我有一个Spring Boot配置类 .
public class RedisCacheConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
@Bean
JedisConnectionFactory jedisConnectionFactory() {
return new JedisConnectionFactory();
}
@Bean
RedisTemplate<Object, Object> redisTemplate() {
RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(jedisConnectionFactory());
return redisTemplate;
}
@Bean
CacheManager cacheManager() {
return new RedisCacheManager(redisTemplate());
}
}
在我的 application.yml
文件中,如何修改 spring.redis.cluster
选项以拥有多个节点,一个有密码?
我使用的是Jedis 1.9.0 .
1 回答
您可以根据需要创建任意数量的连接工厂,使用它们创建多个
RedisTemplate
beans,然后创建多个CacheManager
beans:然后,使用如下配置(YAML中的示例):
您可以使用创建的缓存管理器和缓存抽象:
如果您使用的是Spring Data Redis,则可能必须排除以下自动配置:
RedisAutoConfiguration
,RedisRepositoriesAutoConfiguration