feat: disables sending HELLO if protocol is -1

This commit is contained in:
ljun20160606 2023-06-28 10:34:43 +08:00
parent f994ff1cd9
commit 646d99e12a
2 changed files with 22 additions and 18 deletions

View File

@ -46,7 +46,8 @@ type Options struct {
OnConnect func(ctx context.Context, cn *Conn) error OnConnect func(ctx context.Context, cn *Conn) error
// Protocol 2 or 3. Use the version to negotiate RESP version with redis-server. // Protocol 2 or 3. Use the version to negotiate RESP version with redis-server.
// Default is 3. // Default is 3; -1 disables sending HELLO means that the version depends on the default
// settings of redis-server.
Protocol int Protocol int
// Use the specified Username to authenticate the current connection // Use the specified Username to authenticate the current connection
// with one of the connections defined in the ACL list when connecting // with one of the connections defined in the ACL list when connecting

View File

@ -280,6 +280,8 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
var auth bool var auth bool
protocol := c.opt.Protocol protocol := c.opt.Protocol
// disables sending HELLO if protocol is lower than 0.
if protocol >= 0 {
// By default, use RESP3 in current version. // By default, use RESP3 in current version.
if protocol < 2 { if protocol < 2 {
protocol = 3 protocol = 3
@ -299,6 +301,7 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
// difficult to rely on error strings to determine all results. // difficult to rely on error strings to determine all results.
return err return err
} }
}
if !c.opt.DisableIndentity { if !c.opt.DisableIndentity {
libName := "" libName := ""
libVer := Version() libVer := Version()