I'm working on an application(Spring) with the following requirements:<ul><li>Read data from Redis Server1</li> <li>Read data from Redis Server2</li> <li>Read data from Redis Server3</li> </ul>
AND<ul><li>Save the information to MySQL.</li> </ul>
Can someone give us a thought to connect to different Redis servers using Spring Data Redis.
Got a link: <a href="http://forum.spring.io/forum/spring-projects/data/nosql/104599-how-to-connect-to-multiple-redis-instances-using-redistemplate?view=stream" rel="nofollow">http://forum.spring.io/forum/spring-projects/data/nosql/104599-how-to-connect-to-multiple-redis-instances-using-redistemplate?view=stream</a>
But that's too old.
Any help would be appreciated.Answer1:
There's not out-of-the-box support for accessing multiple servers at once but you can get there yourself.
Usually, you would use <a href="http://docs.spring.io/spring-data/data-redis/docs/current/api/org/springframework/data/redis/core/RedisTemplate.html" rel="nofollow">
RedisTemplate</a> to interact with Redis.
RedisTemplate uses <a href="http://docs.spring.io/spring-data/data-redis/docs/current/api/org/springframework/data/redis/connection/RedisConnectionFactory.html" rel="nofollow">
RedisConnectionFactory</a> 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
Spring Framework provides something similar for JDBC with <a href="https://github.com/spring-projects/spring-framework/blob/master/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java" rel="nofollow">
AbstractRoutingDataSource</a>. The code at GitHub should give you an approach how to implement a routing