feat: no longer verify HELLO error messages (#2515)

Signed-off-by: monkey92t <golang@88.com>
This commit is contained in:
Monkey 2023-04-12 20:35:32 +08:00 committed by GitHub
parent 6edb1529ff
commit 7b4f2179cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 6 deletions

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"net" "net"
"strings"
"sync/atomic" "sync/atomic"
"time" "time"
@ -281,13 +280,18 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
var auth bool var auth bool
// For redis-server < 6.0 that does not support the Hello command, // for redis-server versions that do not support the HELLO command,
// we continue to provide services with RESP2. // RESP2 will continue to be used.
if err := conn.Hello(ctx, 3, username, password, "").Err(); err == nil { if err := conn.Hello(ctx, 3, username, password, "").Err(); err == nil {
auth = true auth = true
} else if !strings.HasPrefix(err.Error(), "ERR unknown command") && } else if !isRedisError(err) {
// this check is for compatibility DragonflyDB. // When the server responds with the RESP protocol and the result is not a normal
!strings.HasPrefix(err.Error(), "NOAUTH Authentication") { // 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 return err
} }