Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lettuce Drivers Fail on RedisHandshake when connecting to GCP Redis 7.2 #2938

Closed
razilevin opened this issue Jul 10, 2024 · 3 comments
Closed
Assignees
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@razilevin
Copy link

Lettuce Library 6.3.0.RELEASE/9bb1669

We have upgraded GCP memory store to version <7.2.x> and now the redis driver fails to connect since the following commands are NOT SUPPORTED

CLIENT SETINFO LIB-NAME
CLIENT SETINFO LIB-VER
Caused by: io.lettuce.core.RedisCommandExecutionException: ERR unknown command 'CLIENT', with args beginning with: 'SETINFO' 'lib-name' 'Lettuce'.

How can we disable this handshake if these settings are hard-coded when building the redis uri object. If we can set the LIB-NAME and LIB-VER to NULL or a blank string the RedisHandshake class will not try to run those commands as seen in this code?

private CompletableFuture<Void> applyPostHandshake(Channel channel, String redisVersion,
            ProtocolVersion negotiatedProtocolVersion) {

        List<AsyncCommand<?, ?, ?>> postHandshake = new ArrayList<>();

        ConnectionMetadata metadata = connectionState.getConnectionMetadata();

        if (metadata.getClientName() != null && negotiatedProtocolVersion == ProtocolVersion.RESP2) {
            postHandshake.add(new AsyncCommand<>(this.commandBuilder.clientSetname(connectionState.getClientName())));
        }

        if (negotiatedProtocolVersion == ProtocolVersion.RESP3) {

            RedisVersion currentVersion = RedisVersion.of(redisVersion);

            if (currentVersion.isGreaterThanOrEqualTo(CLIENT_SET_INFO_SINCE)) {

                if (LettuceStrings.isNotEmpty(metadata.getLibraryName())) {
                    postHandshake
                            .add(new AsyncCommand<>(this.commandBuilder.clientSetinfo("lib-name", metadata.getLibraryName())));
                }

                if (LettuceStrings.isNotEmpty(metadata.getLibraryVersion())) {
                    postHandshake.add(
                            new AsyncCommand<>(this.commandBuilder.clientSetinfo("lib-ver", metadata.getLibraryVersion())));
                }
            }
        }

        if (connectionState.getDb() > 0) {
            postHandshake.add(new AsyncCommand<>(this.commandBuilder.select(connectionState.getDb())));
        }

        if (connectionState.isReadOnly()) {
            postHandshake.add(new AsyncCommand<>(this.commandBuilder.readOnly()));
        }

        if (postHandshake.isEmpty()) {
            return CompletableFuture.completedFuture(null);
        }

        return dispatch(channel, postHandshake);
    }
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 10, 2024
@razilevin
Copy link
Author

First Hack to fix

Override the default Lettuce Connection Factory.

    @Bean
    public LettuceConnectionFactory factory() {
        return new LettuceConnectionFactory() {
            @NonNull
            protected AbstractRedisClient createClient() {

                var builder = RedisURI.Builder.redis("localhost", 6379);

                getClientConfiguration().getClientName()
                                        .ifPresent(builder::withClientName);

                builder.withDatabase(getDatabase());
                builder.withSsl(getClientConfiguration().isUseSsl());
                builder.withVerifyPeer(getClientConfiguration().isVerifyPeer());
                builder.withStartTls(getClientConfiguration().isStartTls());
                builder.withTimeout(getClientConfiguration().getCommandTimeout());
                builder.withLibraryName("");
                builder.withLibraryVersion("");

                var uri = builder.build();

                RedisClient redisClient = getClientConfiguration().getClientResources()
                                                                  .map(clientResources -> RedisClient.create(clientResources, uri))
                                                                  .orElseGet(() -> RedisClient.create(uri));

                getClientConfiguration().getClientOptions()
                                        .ifPresent(redisClient::setOptions);

                return redisClient;
            }


        };
    }

@tishun
Copy link
Contributor

tishun commented Jul 12, 2024

For more information please take a look at redis/lettuce#2817

@christophstrobl christophstrobl self-assigned this Jul 15, 2024
@christophstrobl
Copy link
Member

Thank you @razilevin for getting in touch and @tishun for chiming in. From a data-redis perspective there don't seem to be any actionable items right now since the issue happens (and is already solved) within the lettuce driver. Please give lettuce:6.4.x a try, which should contain the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

4 participants