forked from mirror/redis
Improve rate limited error message.
This commit is contained in:
parent
c66f542b4f
commit
9c17ce2d93
16
pool.go
16
pool.go
|
@ -3,6 +3,7 @@ package redis
|
||||||
import (
|
import (
|
||||||
"container/list"
|
"container/list"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -13,7 +14,6 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errClosed = errors.New("redis: client is closed")
|
errClosed = errors.New("redis: client is closed")
|
||||||
errRateLimited = errors.New("redis: you open connections too fast")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -100,6 +100,8 @@ type connPool struct {
|
||||||
|
|
||||||
idleNum int
|
idleNum int
|
||||||
closed bool
|
closed bool
|
||||||
|
|
||||||
|
lastDialErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func newConnPool(dial func() (*conn, error), opt *options) *connPool {
|
func newConnPool(dial func() (*conn, error), opt *options) *connPool {
|
||||||
|
@ -116,9 +118,17 @@ func newConnPool(dial func() (*conn, error), opt *options) *connPool {
|
||||||
|
|
||||||
func (p *connPool) new() (*conn, error) {
|
func (p *connPool) new() (*conn, error) {
|
||||||
if !p.rl.Check() {
|
if !p.rl.Check() {
|
||||||
return nil, errRateLimited
|
err := fmt.Errorf(
|
||||||
|
"redis: you open connections too fast (last error: %s)",
|
||||||
|
p.lastDialErr,
|
||||||
|
)
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return p.dial()
|
cn, err := p.dial()
|
||||||
|
if err != nil {
|
||||||
|
p.lastDialErr = err
|
||||||
|
}
|
||||||
|
return cn, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *connPool) Get() (*conn, bool, error) {
|
func (p *connPool) Get() (*conn, bool, error) {
|
||||||
|
|
Loading…
Reference in New Issue