My old config like
spring.redis.host=192.168.1.1
Now I want to modify
spring.redis.host=192.168.1.2
But need not restart My project, How can I do that?
My old config like
spring.redis.host=192.168.1.1
Now I want to modify
spring.redis.host=192.168.1.2
But need not restart My project, How can I do that?
ok, I found the answer:
RedisTemplate template = (RedisTemplate) applicationContext.getBean("redisTemplate");
JedisConnectionFactory redisConnectionFactory = (JedisConnectionFactory) template.getConnectionFactory();
//关闭连接池
redisConnectionFactory.destroy();
redisConnectionFactory.setShardInfo(null);
redisConnectionFactory.setHostName(host);
redisConnectionFactory.setPort(port);
redisConnectionFactory.setPassword(password);
redisConnectionFactory.setDatabase(database);
//重新创建连接池
redisConnectionFactory.afterPropertiesSet();
template.setConnectionFactory(redisConnectionFactory);