From 3805610dff220fc0786a6f737fbe2c7aa7f26af2 Mon Sep 17 00:00:00 2001 From: zhangjianfeng_dxm Date: Thu, 9 Nov 2023 13:28:20 +0800 Subject: [PATCH] Add DisableHelloCmd options --- options.go | 4 ++++ redis.go | 28 +++++++++++++++------------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/options.go b/options.go index 449a9252..00e49d2a 100644 --- a/options.go +++ b/options.go @@ -144,6 +144,10 @@ type Options struct { // Disable set-lib on connect. Default is false. DisableIndentity bool + + // Disable Hello on connect. Default is false. + // Hello is used to check the server version,but in Enterprise environment with twproxy,it will cause error,return EOF panic. + DisableHelloCmd bool } func (opt *Options) init() { diff --git a/redis.go b/redis.go index 9430eb75..1cdd2ad8 100644 --- a/redis.go +++ b/redis.go @@ -285,19 +285,21 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error { protocol = 3 } - // for redis-server versions that do not support the HELLO command, - // RESP2 will continue to be used. - if err := conn.Hello(ctx, protocol, username, password, "").Err(); err == nil { - auth = true - } else if !isRedisError(err) { - // When the server responds with the RESP protocol and the result is not a normal - // execution result of the HELLO command, we consider it to be an indication that - // the server does not support the HELLO command. - // The server may be a redis-server that does not support the HELLO command, - // or it could be DragonflyDB or a third-party redis-proxy. They all respond - // with different error string results for unsupported commands, making it - // difficult to rely on error strings to determine all results. - return err + if !c.opt.DisableHelloCmd { + // for redis-server versions that do not support the HELLO command, + // RESP2 will continue to be used. + if err := conn.Hello(ctx, protocol, username, password, "").Err(); err == nil { + auth = true + } else if !isRedisError(err) { + // When the server responds with the RESP protocol and the result is not a normal + // execution result of the HELLO command, we consider it to be an indication that + // the server does not support the HELLO command. + // The server may be a redis-server that does not support the HELLO command, + // or it could be DragonflyDB or a third-party redis-proxy. They all respond + // with different error string results for unsupported commands, making it + // difficult to rely on error strings to determine all results. + return err + } } if !c.opt.DisableIndentity { libName := ""