Close single conn connection pool

This commit is contained in:
Patrick White 2019-08-01 14:59:53 -07:00
parent 0cf98f9217
commit efa4a78883
2 changed files with 21 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package internal
import (
"context"
"errors"
"io"
"net"
"strings"
@ -9,6 +10,8 @@ import (
"github.com/go-redis/redis/internal/proto"
)
var ErrSingleConnPoolClosed = errors.New("redis: SingleConnPool is closed")
func IsRetryableError(err error, retryTimeout bool) bool {
switch err {
case nil, context.Canceled, context.DeadlineExceeded:
@ -22,6 +25,10 @@ func IsRetryableError(err error, retryTimeout bool) bool {
}
return true
}
if err == ErrSingleConnPoolClosed {
return true
}
s := err.Error()
if s == "ERR max number of clients reached" {
return true

View File

@ -1,9 +1,14 @@
package pool
import "context"
import (
"context"
"github.com/go-redis/redis/internal"
)
type SingleConnPool struct {
cn *Conn
cnClosed bool
}
var _ Pooler = (*SingleConnPool)(nil)
@ -23,6 +28,9 @@ func (p *SingleConnPool) CloseConn(*Conn) error {
}
func (p *SingleConnPool) Get(ctx context.Context) (*Conn, error) {
if p.cnClosed {
return nil, internal.ErrSingleConnPoolClosed
}
return p.cn, nil
}
@ -36,9 +44,13 @@ func (p *SingleConnPool) Remove(cn *Conn) {
if p.cn != cn {
panic("p.cn != cn")
}
p.cnClosed = true
}
func (p *SingleConnPool) Len() int {
if p.cnClosed {
return 0
}
return 1
}