Caused by: io.lettuce.core.RedisCommandExecutionException: MOVED 8731 172.19.122.164:6379

Viewed 3568

We have a spring-boot application which is deployed to tomcat contained in EC2 instance in AWS. In local I have redis setup. And in my application.yml my redis configuration look like this:

redis:
  enabled: true
  clusterNodes: localhost:6379
  properties:
    lockExpiryMillis: 3000
    lockRetryAttempts: 3
    lockRetryWaitMillis: 50

We were configuring it in java as shown below:

       {
           RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(clusterNodes.get(0).split(":")[0]);
           return new LettuceConnectionFactory(config);
       }
       RedisClusterConfiguration config = new RedisClusterConfiguration(clusterNodes);

while my cluster load balancer url in QA is something like below:

aq************amazonaws.com:6379 which actually hides all the redis cluster.

I tested with this configuration in local......with QA url as well.

But getting the exception continously

Caused by: io.lettuce.core.RedisCommandExecutionException: MOVED 8731 172.19.122.164:6379

Note:The versions and properties are fine, since it is working in local without any exception

1 Answers

So the issue was actually silly...... I was configuring RedisStandaloneConfiguration when count is 1..... Though in my case I wasn't getting the actual redis URL instead I was just getting local balancer single redis url.

In QA when i updated the redis url with the actual once separated by , it was working fine, means no Caused by: io.lettuce.core.RedisCommandExecutionException.

Since we were supposed to use the load balancer url and not the actual ones I had to update code to start redis in standalone mode only when it is localhost(since ofcourse cluster is not configured) while at all the other time I am starting it in RedisClusterConfiguration.

Changed code part:

 if(clusterNodes.contains("localhost"))
        {
            RedisStandaloneConfiguration config = new RedisStandaloneConfiguration("localhost");
            return new LettuceConnectionFactory(config);
        }
        
        RedisClusterConfiguration config = new RedisClusterConfiguration(Arrays.asList(clusterNodes));
Related