skip to Main Content

We have a spring-boot application which is deployed to lambda in AWS.
Code

public AbstractRedisClient getClient(String host, String port) {
        LOG.info("redis-uri" + "redis://"+host+":"+port);
        return RedisClient.create("redis://"+host+":"+port);
    }

    /**
     * Returns the Redis connection using the Lettuce-Redis-Client
     *
     * @return RedisClient
     */
    public RedisClient getConnection(String host, String port) {
        LOG.info("redis-Host " + host);
        LOG.info("redis-Port " + port);
        RedisClient redisClient = (RedisClient) getClient(host, port);
        redisClient.setDefaultTimeout(Duration.ofSeconds(10));
        return redisClient;
    }


 private RedisCommands<String, String> getRedisCommands() {
        StatefulRedisConnection<String, String> statefulConnection = openConnection();
        if(statefulConnection != null)
          return statefulConnection.sync();
        else
          return null;
      }
    
      public StatefulRedisConnection<String, String> openConnection() {
    
        if(connection != null && connection.isOpen()) {
          return connection;
        }
        
        String redisPort = "6379";
        String redisHost = environment.getProperty("REDIS_HOST");
        //String redisPort = environment.getProperty("REDIS_PORT");
        LOG.info("Host: {}", redisHost);
        LOG.info("Port: {}", redisPort);
        UnifiedReservationRedisConfig lettuceRedisConfig = new UnifiedReservationRedisConfig();
        String redisUri = "redis://"+redisHost+":"+redisPort;
        redisClient = lettuceRedisConfig.getConnection(redisHost, redisPort);
    
        ConnectionFuture<StatefulRedisConnection<String, String>> future = redisClient
            .connectAsync(StringCodec.UTF8, RedisURI.create(redisUri));
        try {
          connection = future.get();
        } catch(InterruptedException | ExecutionException exception) {
            LOG.info(exception.getMessage());
          closeConnectionsAsync();
          connection = null;
          Thread.currentThread().interrupt();
        }
        return connection;
      }
    
      private void closeConnectionsAsync() {
        LOG.info("Close redis connection");
        if(connection != null && connection.isOpen()) {
          connection.closeAsync();
        }
        if(redisClient != null) {
          redisClient.shutdownAsync();
        }
      }

The issue was happening all time, But frequently geting this issue like Caused by io.lettuce.core.rediscommandexecutionexception: moved 15596 XX.X.XXX.XX:6379, Any one can help to solve this issue

2

Answers


  1. As per my knowledge, you are doing port-forwarding to your redis cluster/instance using port 15596 but the actual redis ports like 6379 are not accessible from your application’s network.
    When redis’s java client get the access to redis then tries to connect to actual ports like 6379.

    Login or Signup to reply.
  2. Try using RedisClusterClient, instead of RedisClient. The unhandled MOVED response indicates that you are trying to use the non-cluster-aware client with Redis deployed in cluster mode.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search