I use spring-data-redis version 1.7.0.M1,and jedis version 2.8.0 Here is my configuration
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
<property name="connectionFactory" ref="redisConnectionFactory"></property>
<property name="keySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashKeySerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="valueSerializer">
<bean class="org.springframework.data.redis.serializer.StringRedisSerializer"/>
</property>
<property name="hashValueSerializer">
<bean class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer"/>
</property>
</bean>
and use 【redisTemplate.opsForValue().get("foo")】 to test
throw the exception
org.springframework.dao.InvalidDataAccessApiUsageException: MOVED 12182 192.168.1.223:7002; nested exception is redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 12182 192.168.1.223:7002
How to config redis-cluster when use spring-data-redis 1.7.0.M1?
Basically all that is needed is setting the inital collection of cluster nodes in
RedisClusterConfiguration
and provide that one toJedisConnectionFactory
orLettuceConnectionFactory
.Spring Boot will provide configuration properties (
spring.redis.cluster.nodes
,spring.redis.cluster.max-redirects
) for working with Redis cluster in the next release. See commit/166a27 for details.The spring-data-examples repository already contains an example of Spring Data Redis cluster support.