Skip to content

Commit

Permalink
fix: respect ctx in cmds run in DialContext (#620)
Browse files Browse the repository at this point in the history
Update DialContext() to use the new DoContext() methods (added in v1.8.6)
when configuring auth/clientName/db during connection creation.

This prevents DialContex() from blocking for a long time if the redis server is
unresponsive.
  • Loading branch information
mitchsw committed Jul 1, 2022
1 parent bcef0d8 commit 95c091f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions redis/conn.go
Expand Up @@ -291,21 +291,21 @@ func DialContext(ctx context.Context, network, address string, options ...DialOp
authArgs = append(authArgs, do.username)
}
authArgs = append(authArgs, do.password)
if _, err := c.Do("AUTH", authArgs...); err != nil {
if _, err := c.DoContext(ctx, "AUTH", authArgs...); err != nil {
netConn.Close()
return nil, err
}
}

if do.clientName != "" {
if _, err := c.Do("CLIENT", "SETNAME", do.clientName); err != nil {
if _, err := c.DoContext(ctx, "CLIENT", "SETNAME", do.clientName); err != nil {
netConn.Close()
return nil, err
}
}

if do.db != 0 {
if _, err := c.Do("SELECT", do.db); err != nil {
if _, err := c.DoContext(ctx, "SELECT", do.db); err != nil {
netConn.Close()
return nil, err
}
Expand Down

0 comments on commit 95c091f

Please sign in to comment.