It's common to connect multiple redis servers in the sample application, currently It's not easy to reuse RedisAutoConfiguration
and LettuceConnectionConfiguration
to create multiple redis related beans, I hope spring-boot could handle this just by adding a few properties, for example:
# primary redis
spring.redis:
host: localhost
port: 6379
# additional redis instances
spring.redis.additional-instances: foo,bar
foo.redis:
host: localhost
port: 6379
database: 1
bar.redis:
host: localhost
port: 6379
database: 2
default redis related beans should be @Primary
// default redis
@Autowired RedisTemplate redisTemplate;
@Autowired RedisTemplate stringRedisTemplate;
// foo redis
@Autowired RedisTemplate fooRedisTemplate;
@Autowired RedisTemplate fooStringRedisTemplate;
// bar redis
@Autowired RedisTemplate barRedisTemplate;
@Autowired RedisTemplate barStringRedisTemplate;
Comment From: quaff
Actually It's impossible to reuse LettuceConnectionConfiguration
since it's not visible.
Comment From: philwebb
This is a general problem with our current design and something that we hope to address more holistically with #21322. I don’t think we’ll be able to tackle the problem in a piecemeal fashion without making things worse. We’d rather keep our existing approach of requiring manual configuration if multiple services are being used until we can find a good general purpose solution.