Spring data redis LettuceConnectionFactory : sharedConnection is shared across multiple RedisTemplate instances resulting in unexpected behavior

22 views Asked by At

I have a requirement of connecting to tow Redis hosts from same application. Host to be connected to is based a runtime condition for failover. I have created 2 RedisTemplate instances with separate LettuceConnectionFactory objects, both with sharedNativeConnection flag as true. I want to use one connection per each redisTemplate. But I have observed that connection is being shared across redisTemplate instances. I have checked in debug mode that when invoking get operation using redisTemplate2, the connection fails with exception(due to an issue with host1) and stacktrace contains host1 socketaddress, whereas host field in standardConfiguration object is host2. What is the way of using shared connection per redisTemplate and not across multiple redisTemplate instances.

0

There are 0 answers