summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-redis/redis/internal
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-redis/redis/internal')
-rw-r--r--vendor/github.com/go-redis/redis/internal/error.go27
-rw-r--r--vendor/github.com/go-redis/redis/internal/pool/pool.go25
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/reader.go2
-rw-r--r--vendor/github.com/go-redis/redis/internal/proto/scan.go2
4 files changed, 32 insertions, 24 deletions
diff --git a/vendor/github.com/go-redis/redis/internal/error.go b/vendor/github.com/go-redis/redis/internal/error.go
index 90f6503a1..0898eeb62 100644
--- a/vendor/github.com/go-redis/redis/internal/error.go
+++ b/vendor/github.com/go-redis/redis/internal/error.go
@@ -12,11 +12,24 @@ type RedisError string
func (e RedisError) Error() string { return string(e) }
-func IsRetryableError(err error) bool {
- return IsNetworkError(err) || err.Error() == "ERR max number of clients reached"
+func IsRetryableError(err error, retryNetError bool) bool {
+ if IsNetworkError(err) {
+ return retryNetError
+ }
+ s := err.Error()
+ if s == "ERR max number of clients reached" {
+ return true
+ }
+ if strings.HasPrefix(s, "LOADING ") {
+ return true
+ }
+ if strings.HasPrefix(s, "CLUSTERDOWN ") {
+ return true
+ }
+ return false
}
-func IsInternalError(err error) bool {
+func IsRedisError(err error) bool {
_, ok := err.(RedisError)
return ok
}
@@ -33,7 +46,7 @@ func IsBadConn(err error, allowTimeout bool) bool {
if err == nil {
return false
}
- if IsInternalError(err) {
+ if IsRedisError(err) {
return false
}
if allowTimeout {
@@ -45,7 +58,7 @@ func IsBadConn(err error, allowTimeout bool) bool {
}
func IsMovedError(err error) (moved bool, ask bool, addr string) {
- if !IsInternalError(err) {
+ if !IsRedisError(err) {
return
}
@@ -69,7 +82,3 @@ func IsMovedError(err error) (moved bool, ask bool, addr string) {
func IsLoadingError(err error) bool {
return strings.HasPrefix(err.Error(), "LOADING ")
}
-
-func IsClusterDownError(err error) bool {
- return strings.HasPrefix(err.Error(), "CLUSTERDOWN ")
-}
diff --git a/vendor/github.com/go-redis/redis/internal/pool/pool.go b/vendor/github.com/go-redis/redis/internal/pool/pool.go
index 25e78aa3c..836ec1045 100644
--- a/vendor/github.com/go-redis/redis/internal/pool/pool.go
+++ b/vendor/github.com/go-redis/redis/internal/pool/pool.go
@@ -23,12 +23,13 @@ var timers = sync.Pool{
// Stats contains pool state information and accumulated stats.
type Stats struct {
- Requests uint32 // number of times a connection was requested by the pool
Hits uint32 // number of times free connection was found in the pool
+ Misses uint32 // number of times free connection was NOT found in the pool
Timeouts uint32 // number of times a wait timeout occurred
- TotalConns uint32 // the number of total connections in the pool
- FreeConns uint32 // the number of free connections in the pool
+ TotalConns uint32 // number of total connections in the pool
+ FreeConns uint32 // number of free connections in the pool
+ StaleConns uint32 // number of stale connections removed from the pool
}
type Pooler interface {
@@ -150,8 +151,6 @@ func (p *ConnPool) Get() (*Conn, bool, error) {
return nil, false, ErrClosed
}
- atomic.AddUint32(&p.stats.Requests, 1)
-
select {
case p.queue <- struct{}{}:
default:
@@ -189,6 +188,8 @@ func (p *ConnPool) Get() (*Conn, bool, error) {
return cn, false, nil
}
+ atomic.AddUint32(&p.stats.Misses, 1)
+
newcn, err := p.NewConn()
if err != nil {
<-p.queue
@@ -265,11 +266,13 @@ func (p *ConnPool) FreeLen() int {
func (p *ConnPool) Stats() *Stats {
return &Stats{
- Requests: atomic.LoadUint32(&p.stats.Requests),
- Hits: atomic.LoadUint32(&p.stats.Hits),
- Timeouts: atomic.LoadUint32(&p.stats.Timeouts),
+ Hits: atomic.LoadUint32(&p.stats.Hits),
+ Misses: atomic.LoadUint32(&p.stats.Misses),
+ Timeouts: atomic.LoadUint32(&p.stats.Timeouts),
+
TotalConns: uint32(p.Len()),
FreeConns: uint32(p.FreeLen()),
+ StaleConns: atomic.LoadUint32(&p.stats.StaleConns),
}
}
@@ -362,10 +365,6 @@ func (p *ConnPool) reaper(frequency time.Duration) {
internal.Logf("ReapStaleConns failed: %s", err)
continue
}
- s := p.Stats()
- internal.Logf(
- "reaper: removed %d stale conns (TotalConns=%d FreeConns=%d Requests=%d Hits=%d Timeouts=%d)",
- n, s.TotalConns, s.FreeConns, s.Requests, s.Hits, s.Timeouts,
- )
+ atomic.AddUint32(&p.stats.StaleConns, uint32(n))
}
}
diff --git a/vendor/github.com/go-redis/redis/internal/proto/reader.go b/vendor/github.com/go-redis/redis/internal/proto/reader.go
index 2159cf639..cd94329d8 100644
--- a/vendor/github.com/go-redis/redis/internal/proto/reader.go
+++ b/vendor/github.com/go-redis/redis/internal/proto/reader.go
@@ -63,7 +63,7 @@ func (p *Reader) ReadLine() ([]byte, error) {
return nil, bufio.ErrBufferFull
}
if len(line) == 0 {
- return nil, internal.RedisError("redis: reply is empty")
+ return nil, fmt.Errorf("redis: reply is empty")
}
if isNilReply(line) {
return nil, internal.Nil
diff --git a/vendor/github.com/go-redis/redis/internal/proto/scan.go b/vendor/github.com/go-redis/redis/internal/proto/scan.go
index 3ab40b94f..0431a877d 100644
--- a/vendor/github.com/go-redis/redis/internal/proto/scan.go
+++ b/vendor/github.com/go-redis/redis/internal/proto/scan.go
@@ -11,7 +11,7 @@ import (
func Scan(b []byte, v interface{}) error {
switch v := v.(type) {
case nil:
- return internal.RedisError("redis: Scan(nil)")
+ return fmt.Errorf("redis: Scan(nil)")
case *string:
*v = internal.BytesToString(b)
return nil