Search code examples
springredisspring-data-redis

how to connect multiple redis instances through spring data redis?


I am trying to connect multiple redis instances via spring. But I did not find any documentation.

Here is how I am using it currently. I am using Jedis as the client and I plan on using Jedis only as I might require support for sentinel.

<bean id="jedisConnFactory"
    class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
    <property name ="hostName" value ="localhost"/>
    <property name="port" value="6379" />   
</bean>

<bean id="stringRedisSerializer"
    class="org.springframework.data.redis.serializer.StringRedisSerializer" />

<!-- redis template definition -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"
    p:connection-factory-ref="jedisConnFactory" 
    p:keySerializer-ref="stringRedisSerializer"
    p:hashKeySerializer-ref="stringRedisSerializer"
    p:ValueSerializer-ref="stringRedisSerializer" />

I want to add multiple redis instances to the connection pool. Like..

<property name ="hosts" value ="localhost:6379,localhost:6380"/>

Solution

  • After researching , I found, there is no support for client side partitioning currently in spring-data-redis.

    In future the partitioning technique in redis shall move to redis-cluster permanently.

    At present, To use partition along with spring-data-redis, the best way is to use twemproxy and point JedisConnectionFactory host and port to twemproxy.