I have clustered redis and trying to insert data in there using redisTemplate. I am getting error below when it reached to line that is trying to put data. "redis.clients.jedis.exceptions.JedisMovedDataException: MOVED" org.springframework.data.redis.ClusterRedirectException: Redirect: slot 7319 to IP addr:6379.; nested exception is redis.clients.jedis.exceptions.JedisMovedDataException: MOVED 7319 IP addr:6379
Any idea? The hostName in the redisConnectionFactory bean is the cluster's Configuration endpoint.
return items -> {
HashOperations<String, String, String> hashOps = redisTemplate.opsForHash();
items.forEach(item -> {
hashOps.put((item.getProgramName()), item.getProgramName(), item.toJson().toString());
});
};
@Bean
public JedisConnectionFactory redisConnectionFactory() {
JedisConnectionFactory redisConnectionFactory = new JedisConnectionFactory();
redisConnectionFactory.setHostName(hostName);
redisConnectionFactory.setPort(port);
return redisConnectionFactory;
}
@Bean(name = "redisTemplate")
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<String, String>();
redisTemplate.setConnectionFactory(redisConnectionFactory());
redisTemplate.setDefaultSerializer(new StringRedisSerializer());
return redisTemplate;
}
You are using a Redis cluster but your configuration is for standalone Jedis connection factory. You should provide RedisClusterConfiguration to create JedisConnectionFactory.
The following posts will help:
http://stackoverflow.com.mevn.net/questions/46667584/springboot-elasticache-jedismoveddataexception-moved
How to config redis-cluster when use spring-data-redis 1.7.0.M1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With