diff --git a/cluster.go b/cluster.go index 9c62fb6a..55bc5bae 100644 --- a/cluster.go +++ b/cluster.go @@ -1272,11 +1272,7 @@ func (c *ClusterClient) defaultProcessPipeline(cmds []Cmder) error { } err = c.pipelineProcessCmds(node, cn, cmds, failedCmds) - if err == nil || internal.IsRedisError(err) { - node.Client.connPool.Put(cn) - } else { - node.Client.connPool.Remove(cn) - } + node.Client.releaseConnStrict(cn, err) }(node, cmds) } @@ -1466,11 +1462,7 @@ func (c *ClusterClient) defaultProcessTxPipeline(cmds []Cmder) error { } err = c.txPipelineProcessCmds(node, cn, cmds, failedCmds) - if err == nil || internal.IsRedisError(err) { - node.Client.connPool.Put(cn) - } else { - node.Client.connPool.Remove(cn) - } + node.Client.releaseConnStrict(cn, err) }(node, cmds) } diff --git a/internal/error.go b/internal/error.go index bda97baa..5feb861e 100644 --- a/internal/error.go +++ b/internal/error.go @@ -9,6 +9,9 @@ import ( ) func IsRetryableError(err error, retryTimeout bool) bool { + if err == nil { + return false + } if err == io.EOF { return true } diff --git a/redis.go b/redis.go index 64056713..92a07fc6 100644 --- a/redis.go +++ b/redis.go @@ -77,14 +77,20 @@ func (c *baseClient) getConn() (*pool.Conn, error) { return cn, nil } -func (c *baseClient) releaseConn(cn *pool.Conn, err error) bool { +func (c *baseClient) releaseConn(cn *pool.Conn, err error) { if internal.IsBadConn(err, false) { c.connPool.Remove(cn) - return false + } else { + c.connPool.Put(cn) } +} - c.connPool.Put(cn) - return true +func (c *baseClient) releaseConnStrict(cn *pool.Conn, err error) { + if err == nil || internal.IsRedisError(err) { + c.connPool.Put(cn) + } else { + c.connPool.Remove(cn) + } } func (c *baseClient) initConn(cn *pool.Conn) error { @@ -248,12 +254,7 @@ func (c *baseClient) generalProcessPipeline(cmds []Cmder, p pipelineProcessor) e } canRetry, err := p(cn, cmds) - - if err == nil || internal.IsRedisError(err) { - c.connPool.Put(cn) - break - } - c.connPool.Remove(cn) + c.releaseConnStrict(cn, err) if !canRetry || !internal.IsRetryableError(err, true) { break diff --git a/ring.go b/ring.go index 42a4e6c1..689f144c 100644 --- a/ring.go +++ b/ring.go @@ -614,11 +614,7 @@ func (c *Ring) defaultProcessPipeline(cmds []Cmder) error { } canRetry, err := shard.Client.pipelineProcessCmds(cn, cmds) - if err == nil || internal.IsRedisError(err) { - shard.Client.connPool.Put(cn) - return - } - shard.Client.connPool.Remove(cn) + shard.Client.releaseConnStrict(cn, err) if canRetry && internal.IsRetryableError(err, true) { mu.Lock()