Skip to content

Commit

Permalink
Improved rate-limiter, use ratelimit package
Browse files Browse the repository at this point in the history
  • Loading branch information
dim committed Mar 25, 2015
1 parent 2dc0bd1 commit e3ba7e7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 82 deletions.
8 changes: 4 additions & 4 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync/atomic"
"time"

"gopkg.in/bsm/ratelimit.v1"
"gopkg.in/bufio.v1"
)

Expand Down Expand Up @@ -102,7 +103,7 @@ func (cn *conn) isIdle(timeout time.Duration) bool {

type connPool struct {
dial func() (*conn, error)
rl *rateLimiter
rl *ratelimit.RateLimiter

opt *options
conns chan *conn
Expand All @@ -116,7 +117,7 @@ type connPool struct {
func newConnPool(dial func() (*conn, error), opt *options) *connPool {
return &connPool{
dial: dial,
rl: newRateLimiter(time.Second, 2*opt.PoolSize),
rl: ratelimit.New(2*opt.PoolSize, time.Second),

opt: opt,
conns: make(chan *conn, opt.PoolSize),
Expand Down Expand Up @@ -160,7 +161,7 @@ func (p *connPool) wait() (*conn, error) {

// Establish a new connection
func (p *connPool) new() (*conn, error) {
if !p.rl.Check() {
if p.rl.Limit() {
err := fmt.Errorf(
"redis: you open connections too fast (last error: %v)",
p.lastDialErr,
Expand Down Expand Up @@ -257,7 +258,6 @@ func (p *connPool) Close() (err error) {
if !atomic.CompareAndSwapInt32(&p.closed, 0, 1) {
return nil
}
p.rl.Close()

for {
if p.Size() < 1 {
Expand Down
53 changes: 0 additions & 53 deletions rate_limit.go

This file was deleted.

25 changes: 0 additions & 25 deletions rate_limit_test.go

This file was deleted.

0 comments on commit e3ba7e7

Please sign in to comment.