Skip to content

Commit

Permalink
Remove SetLimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Feb 2, 2020
1 parent 4eb2deb commit db45a82
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
- 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.
- `SetLimiter` is removed and added `Options.Limiter` instead.

## v6.15

Expand Down
7 changes: 5 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type Limiter interface {
// If operation is allowed client must ReportResult of the operation
// whether it is a success or a failure.
Allow() error
// ReportResult reports the result of previously allowed operation.
// nil indicates a success, non-nil error indicates a failure.
// ReportResult reports the result of the previously allowed operation.
// nil indicates a success, non-nil error usually indicates a failure.
ReportResult(result error)
}

Expand Down Expand Up @@ -96,6 +96,9 @@ type Options struct {

// TLS Config to use. When set TLS will be negotiated.
TLSConfig *tls.Config

// Limiter interface used to implemented circuit breaker or rate limiter.
Limiter Limiter
}

func (opt *Options) init() {
Expand Down
18 changes: 6 additions & 12 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) error {
type baseClient struct {
opt *Options
connPool pool.Pooler
limiter Limiter

onClose func() error // hook called when client is closed
}
Expand All @@ -156,17 +155,17 @@ func (c *baseClient) newConn(ctx context.Context) (*pool.Conn, error) {
}

func (c *baseClient) getConn(ctx context.Context) (*pool.Conn, error) {
if c.limiter != nil {
err := c.limiter.Allow()
if c.opt.Limiter != nil {
err := c.opt.Limiter.Allow()
if err != nil {
return nil, err
}
}

cn, err := c._getConn(ctx)
if err != nil {
if c.limiter != nil {
c.limiter.ReportResult(err)
if c.opt.Limiter != nil {
c.opt.Limiter.ReportResult(err)
}
return nil, err
}
Expand Down Expand Up @@ -234,8 +233,8 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
}

func (c *baseClient) releaseConn(cn *pool.Conn, err error) {
if c.limiter != nil {
c.limiter.ReportResult(err)
if c.opt.Limiter != nil {
c.opt.Limiter.ReportResult(err)
}

if isBadConn(err, false) {
Expand Down Expand Up @@ -553,11 +552,6 @@ func (c *Client) Options() *Options {
return c.opt
}

func (c *Client) SetLimiter(l Limiter) *Client {
c.limiter = l
return c
}

type PoolStats pool.Stats

// PoolStats returns connection pool stats.
Expand Down

0 comments on commit db45a82

Please sign in to comment.