forked from mirror/redis
Remove SetLimiter
This commit is contained in:
parent
4eb2debcdc
commit
db45a825cc
|
@ -10,6 +10,7 @@
|
||||||
- Client listens on Context.Done while waiting for a connection from the pool and returns an error when context context is cancelled.
|
- Client listens on Context.Done while waiting for a connection from the pool and returns an error when context context is cancelled.
|
||||||
- Add PubSub.ChannelWithSubscriptions that sends `*Subscription` in addition to `*Message` to allow detecting reconnections.
|
- Add PubSub.ChannelWithSubscriptions that sends `*Subscription` in addition to `*Message` to allow detecting reconnections.
|
||||||
- `time.Time` is now marshalled in RFC3339 format. `rdb.Get("foo").Time()` helper is added to parse time.
|
- `time.Time` is now marshalled in RFC3339 format. `rdb.Get("foo").Time()` helper is added to parse time.
|
||||||
|
- `SetLimiter` is removed and added `Options.Limiter` instead.
|
||||||
|
|
||||||
## v6.15
|
## v6.15
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,8 @@ type Limiter interface {
|
||||||
// If operation is allowed client must ReportResult of the operation
|
// If operation is allowed client must ReportResult of the operation
|
||||||
// whether it is a success or a failure.
|
// whether it is a success or a failure.
|
||||||
Allow() error
|
Allow() error
|
||||||
// ReportResult reports the result of previously allowed operation.
|
// ReportResult reports the result of the previously allowed operation.
|
||||||
// nil indicates a success, non-nil error indicates a failure.
|
// nil indicates a success, non-nil error usually indicates a failure.
|
||||||
ReportResult(result error)
|
ReportResult(result error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +96,9 @@ type Options struct {
|
||||||
|
|
||||||
// TLS Config to use. When set TLS will be negotiated.
|
// TLS Config to use. When set TLS will be negotiated.
|
||||||
TLSConfig *tls.Config
|
TLSConfig *tls.Config
|
||||||
|
|
||||||
|
// Limiter interface used to implemented circuit breaker or rate limiter.
|
||||||
|
Limiter Limiter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (opt *Options) init() {
|
func (opt *Options) init() {
|
||||||
|
|
18
redis.go
18
redis.go
|
@ -131,7 +131,6 @@ func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) error {
|
||||||
type baseClient struct {
|
type baseClient struct {
|
||||||
opt *Options
|
opt *Options
|
||||||
connPool pool.Pooler
|
connPool pool.Pooler
|
||||||
limiter Limiter
|
|
||||||
|
|
||||||
onClose func() error // hook called when client is closed
|
onClose func() error // hook called when client is closed
|
||||||
}
|
}
|
||||||
|
@ -156,8 +155,8 @@ func (c *baseClient) newConn(ctx context.Context) (*pool.Conn, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *baseClient) getConn(ctx context.Context) (*pool.Conn, error) {
|
func (c *baseClient) getConn(ctx context.Context) (*pool.Conn, error) {
|
||||||
if c.limiter != nil {
|
if c.opt.Limiter != nil {
|
||||||
err := c.limiter.Allow()
|
err := c.opt.Limiter.Allow()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -165,8 +164,8 @@ func (c *baseClient) getConn(ctx context.Context) (*pool.Conn, error) {
|
||||||
|
|
||||||
cn, err := c._getConn(ctx)
|
cn, err := c._getConn(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if c.limiter != nil {
|
if c.opt.Limiter != nil {
|
||||||
c.limiter.ReportResult(err)
|
c.opt.Limiter.ReportResult(err)
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -234,8 +233,8 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *baseClient) releaseConn(cn *pool.Conn, err error) {
|
func (c *baseClient) releaseConn(cn *pool.Conn, err error) {
|
||||||
if c.limiter != nil {
|
if c.opt.Limiter != nil {
|
||||||
c.limiter.ReportResult(err)
|
c.opt.Limiter.ReportResult(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if isBadConn(err, false) {
|
if isBadConn(err, false) {
|
||||||
|
@ -553,11 +552,6 @@ func (c *Client) Options() *Options {
|
||||||
return c.opt
|
return c.opt
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) SetLimiter(l Limiter) *Client {
|
|
||||||
c.limiter = l
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
type PoolStats pool.Stats
|
type PoolStats pool.Stats
|
||||||
|
|
||||||
// PoolStats returns connection pool stats.
|
// PoolStats returns connection pool stats.
|
||||||
|
|
Loading…
Reference in New Issue