Skip to content

Commit

Permalink
新增方法解决并发添加redisconn问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuCheer committed Jul 24, 2020
1 parent 035e3bf commit 1d6d861
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ func (tb *Bucket) TakeAvailable(count int64) int64 {
return tb.takeAvailable(tb.clock.Now(), count)
}

func (tb *Bucket) TakeAvailableWaitWithRedis(count int64, maxWait time.Duration, conn redis.Conn) (token int64) {
tb.mu.Lock()
defer tb.mu.Unlock()
tb.redisConn = conn

return tb.TakeAvailableWait(count, maxWait)
}


func (tb *Bucket) TakeAvailableWait(count int64, maxWait time.Duration) (token int64) {
timer := time.NewTimer(maxWait)
for {
Expand Down

0 comments on commit 1d6d861

Please sign in to comment.