7

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;
}
user5796415
  • 71
  • 1
  • 3

1 Answers1

10

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

moonlighter
  • 541
  • 3
  • 14
  • your link has an error, should be: https://stackoverflow.com/questions/46667584/springboot-elasticache-jedismoveddataexception-moved – slashdottir Apr 17 '19 at 18:11