From 48224a399f432088134af1c2bde74698260b834a Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Thu, 8 Aug 2019 10:43:10 +0300 Subject: [PATCH] Remove releaseConnStrict --- cluster.go | 4 ++-- error.go | 7 ++++--- redis.go | 14 +------------- ring.go | 2 +- 4 files changed, 8 insertions(+), 19 deletions(-) diff --git a/cluster.go b/cluster.go index bd16fe1e..d65fbffc 100644 --- a/cluster.go +++ b/cluster.go @@ -1075,7 +1075,7 @@ func (c *ClusterClient) _processPipeline(ctx context.Context, cmds []Cmder) erro } err = c.pipelineProcessCmds(ctx, node, cn, cmds, failedCmds) - node.Client.releaseConnStrict(cn, err) + node.Client.releaseConn(cn, err) }(node, cmds) } @@ -1282,7 +1282,7 @@ func (c *ClusterClient) _processTxPipeline(ctx context.Context, cmds []Cmder) er } err = c.txPipelineProcessCmds(ctx, node, cn, cmds, failedCmds) - node.Client.releaseConnStrict(cn, err) + node.Client.releaseConn(cn, err) }(node, cmds) } diff --git a/error.go b/error.go index c0e561dd..0ab014de 100644 --- a/error.go +++ b/error.go @@ -45,12 +45,13 @@ func isRedisError(err error) bool { } func isBadConn(err error, allowTimeout bool) bool { - switch err { - case nil: + if err == nil { return false } if isRedisError(err) { - return isReadOnlyError(err) // #790 + // Close connections in read only state in case domain addr is used + // and domain resolves to a different Redis Server. See #790. + return isReadOnlyError(err) } if allowTimeout { if netErr, ok := err.(net.Error); ok && netErr.Timeout() { diff --git a/redis.go b/redis.go index c7b12ec0..66955763 100644 --- a/redis.go +++ b/redis.go @@ -235,18 +235,6 @@ func (c *baseClient) releaseConn(cn *pool.Conn, err error) { } } -func (c *baseClient) releaseConnStrict(cn *pool.Conn, err error) { - if c.limiter != nil { - c.limiter.ReportResult(err) - } - - if err == nil || isRedisError(err) { - c.connPool.Put(cn) - } else { - c.connPool.Remove(cn, err) - } -} - func (c *baseClient) process(ctx context.Context, cmd Cmder) error { for attempt := 0; attempt <= c.opt.MaxRetries; attempt++ { if attempt > 0 { @@ -351,7 +339,7 @@ func (c *baseClient) generalProcessPipeline( } canRetry, err := p(ctx, cn, cmds) - c.releaseConnStrict(cn, err) + c.releaseConn(cn, err) if !canRetry || !isRetryableError(err, true) { break diff --git a/ring.go b/ring.go index 30d87d24..5b7a7b92 100644 --- a/ring.go +++ b/ring.go @@ -660,7 +660,7 @@ func (c *Ring) generalProcessPipeline( } else { canRetry, err = shard.Client.pipelineProcessCmds(ctx, cn, cmds) } - shard.Client.releaseConnStrict(cn, err) + shard.Client.releaseConn(cn, err) if canRetry && isRetryableError(err, true) { mu.Lock()