Skip to content

Commit db45a82

Browse files
committed
Remove SetLimiter
1 parent 4eb2deb commit db45a82

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- Client listens on Context.Done while waiting for a connection from the pool and returns an error when context context is cancelled.
1111
- Add PubSub.ChannelWithSubscriptions that sends `*Subscription` in addition to `*Message` to allow detecting reconnections.
1212
- `time.Time` is now marshalled in RFC3339 format. `rdb.Get("foo").Time()` helper is added to parse time.
13+
- `SetLimiter` is removed and added `Options.Limiter` instead.
1314

1415
## v6.15
1516

options.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ type Limiter interface {
2121
// If operation is allowed client must ReportResult of the operation
2222
// whether it is a success or a failure.
2323
Allow() error
24-
// ReportResult reports the result of previously allowed operation.
25-
// nil indicates a success, non-nil error indicates a failure.
24+
// ReportResult reports the result of the previously allowed operation.
25+
// nil indicates a success, non-nil error usually indicates a failure.
2626
ReportResult(result error)
2727
}
2828

@@ -96,6 +96,9 @@ type Options struct {
9696

9797
// TLS Config to use. When set TLS will be negotiated.
9898
TLSConfig *tls.Config
99+
100+
// Limiter interface used to implemented circuit breaker or rate limiter.
101+
Limiter Limiter
99102
}
100103

101104
func (opt *Options) init() {

redis.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ func (hs hooks) afterProcessPipeline(ctx context.Context, cmds []Cmder) error {
131131
type baseClient struct {
132132
opt *Options
133133
connPool pool.Pooler
134-
limiter Limiter
135134

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

158157
func (c *baseClient) getConn(ctx context.Context) (*pool.Conn, error) {
159-
if c.limiter != nil {
160-
err := c.limiter.Allow()
158+
if c.opt.Limiter != nil {
159+
err := c.opt.Limiter.Allow()
161160
if err != nil {
162161
return nil, err
163162
}
164163
}
165164

166165
cn, err := c._getConn(ctx)
167166
if err != nil {
168-
if c.limiter != nil {
169-
c.limiter.ReportResult(err)
167+
if c.opt.Limiter != nil {
168+
c.opt.Limiter.ReportResult(err)
170169
}
171170
return nil, err
172171
}
@@ -234,8 +233,8 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
234233
}
235234

236235
func (c *baseClient) releaseConn(cn *pool.Conn, err error) {
237-
if c.limiter != nil {
238-
c.limiter.ReportResult(err)
236+
if c.opt.Limiter != nil {
237+
c.opt.Limiter.ReportResult(err)
239238
}
240239

241240
if isBadConn(err, false) {
@@ -553,11 +552,6 @@ func (c *Client) Options() *Options {
553552
return c.opt
554553
}
555554

556-
func (c *Client) SetLimiter(l Limiter) *Client {
557-
c.limiter = l
558-
return c
559-
}
560-
561555
type PoolStats pool.Stats
562556

563557
// PoolStats returns connection pool stats.

0 commit comments

Comments
 (0)