Skip to content

Commit 928211c

Browse files
committed
chore: set the default value for the options.protocol in the init() of options
Signed-off-by: fukua95 <[email protected]>
1 parent 03c2c0b commit 928211c

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

options.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ func (opt *Options) init() {
178178
opt.Network = "tcp"
179179
}
180180
}
181+
if opt.Protocol < 2 {
182+
opt.Protocol = 3
183+
}
181184
if opt.DialTimeout == 0 {
182185
opt.DialTimeout = 5 * time.Second
183186
}

redis.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,9 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
302302
conn := newConn(c.opt, connPool)
303303

304304
var auth bool
305-
protocol := c.opt.Protocol
306-
// By default, use RESP3 in current version.
307-
if protocol < 2 {
308-
protocol = 3
309-
}
310-
311305
// for redis-server versions that do not support the HELLO command,
312306
// RESP2 will continue to be used.
313-
if err = conn.Hello(ctx, protocol, username, password, c.opt.ClientName).Err(); err == nil {
307+
if err = conn.Hello(ctx, c.opt.Protocol, username, password, c.opt.ClientName).Err(); err == nil {
314308
auth = true
315309
} else if !isRedisError(err) {
316310
// When the server responds with the RESP protocol and the result is not a normal

0 commit comments

Comments
 (0)