Help Center/ Distributed Cache Service/ FAQs/ Client and Network Connection/ What Can I Do If a Lettuce 6.x Client Is Incompatible with My DCS Instance?
Updated on 2022-09-15 GMT+08:00

What Can I Do If a Lettuce 6.x Client Is Incompatible with My DCS Instance?

Symptom

When a Lettuce 6.x client is connected to a Proxy Cluster DCS Redis 4.x/5.x instance, the error message "NOAUTH Authentication required" is displayed.

Figure 1 Error message example

Analysis

In Lettuce 6.x and later versions, the HELLO command of RESP3 (introduced in Redis 6.x) is used to determine the version adaptation. Instances of earlier versions that do not support the HELLO command may encounter compatibility issues. For these instances, you can specify the RESP2 mode (compatible with Redis versions 4 and 5) in Lettuce.

Solution

Add the following code to use RESP2 protocol for accessing Redis:

package com.chinaroad.parking.config;

import io.lettuce.core.ClientOptions;
import io.lettuce.core.protocol.ProtocolVersion;
import org.springframework.boot.autoconfigure.data.redis.LettuceClientConfigurationBuilderCustomizer;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;

@Configuration
public class SpringConfig implements LettuceClientConfigurationBuilderCustomizer {

    @Override
    public void customize(LettuceClientConfiguration.LettuceClientConfigurationBuilder clientConfigurationBuilder) {
        // manually specifying RESP2 
        clientConfigurationBuilder.clientOptions(ClientOptions.builder()
                .protocolVersion(ProtocolVersion.RESP2)
                .build());
    }

}