mirror of
https://github.com/redis/go-redis.git
synced 2025-07-31 05:04:23 +03:00
Remove dial limiter.
This commit is contained in:
@ -8,8 +8,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"gopkg.in/bsm/ratelimit.v1"
|
||||
|
||||
"gopkg.in/redis.v5/internal"
|
||||
)
|
||||
|
||||
@ -49,9 +47,8 @@ type Pooler interface {
|
||||
type dialer func() (net.Conn, error)
|
||||
|
||||
type ConnPool struct {
|
||||
_dial dialer
|
||||
DialLimiter *ratelimit.RateLimiter
|
||||
OnClose func(*Conn) error
|
||||
dial dialer
|
||||
OnClose func(*Conn) error
|
||||
|
||||
poolTimeout time.Duration
|
||||
idleTimeout time.Duration
|
||||
@ -74,8 +71,7 @@ var _ Pooler = (*ConnPool)(nil)
|
||||
|
||||
func NewConnPool(dial dialer, poolSize int, poolTimeout, idleTimeout, idleCheckFrequency time.Duration) *ConnPool {
|
||||
p := &ConnPool{
|
||||
_dial: dial,
|
||||
DialLimiter: ratelimit.New(3*poolSize, time.Second),
|
||||
dial: dial,
|
||||
|
||||
poolTimeout: poolTimeout,
|
||||
idleTimeout: idleTimeout,
|
||||
@ -90,23 +86,6 @@ func NewConnPool(dial dialer, poolSize int, poolTimeout, idleTimeout, idleCheckF
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *ConnPool) dial() (net.Conn, error) {
|
||||
if p.DialLimiter != nil && p.DialLimiter.Limit() {
|
||||
err := fmt.Errorf(
|
||||
"redis: you open connections too fast (last_error=%q)",
|
||||
p.loadLastErr(),
|
||||
)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cn, err := p._dial()
|
||||
if err != nil {
|
||||
p.storeLastErr(err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return cn, nil
|
||||
}
|
||||
|
||||
func (p *ConnPool) NewConn() (*Conn, error) {
|
||||
netConn, err := p.dial()
|
||||
if err != nil {
|
||||
@ -292,7 +271,6 @@ func (p *ConnPool) Close() error {
|
||||
}
|
||||
|
||||
func (p *ConnPool) closeConn(cn *Conn, reason error) error {
|
||||
p.storeLastErr(reason.Error())
|
||||
if p.OnClose != nil {
|
||||
_ = p.OnClose(cn)
|
||||
}
|
||||
@ -356,17 +334,6 @@ func (p *ConnPool) reaper(frequency time.Duration) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ConnPool) storeLastErr(err string) {
|
||||
p.lastErr.Store(err)
|
||||
}
|
||||
|
||||
func (p *ConnPool) loadLastErr() string {
|
||||
if v := p.lastErr.Load(); v != nil {
|
||||
return v.(string)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
var idleCheckFrequency atomic.Value
|
||||
|
Reference in New Issue
Block a user