Connections to multiple Redis servers with Spring Data Redis

二次信任 提交于 2019-12-04 17:40:09

There's not out-of-the-box support for accessing multiple servers at once but you can get there yourself.

Usually, you would use RedisTemplate to interact with Redis. RedisTemplate uses RedisConnectionFactory to obtain a connection per requests. You can implement RedisConnectionFactory yourself and dispatch getConnection() calls to the connection factory that is configured with your server. A Map<String, RedisConnectionFactory> can hold multiple connection factories. You would dispatch by a custom discriminator (usually something that you set on ThreadLocal level).

Spring Framework provides something similar for JDBC with AbstractRoutingDataSource. The code at GitHub should give you an approach how to implement a routing RedisConnectionFactory.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!