Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error redis.clients.jedis.exceptions.JedisMovedDataException: MOVED

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;
}
like image 660
user5796415 Avatar asked Jul 05 '18 19:07

user5796415


1 Answers

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

like image 144
moonlighter Avatar answered Nov 15 '22 09:11

moonlighter