Skip to content

Commit

Permalink
Use redis universal client in token bucket
Browse files Browse the repository at this point in the history
Updated the client to a UniversalClient, which works for redis pools as well as single redis servers.
  • Loading branch information
BrianLeishman authored Feb 28, 2024
1 parent 50bb6c3 commit 5fbdd3c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tokenbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ func redisKey(prefix, key string) string {
// Although depending on a persistence and a cluster configuration some data might be lost in case of a failure
// resulting in an under-limiting the accesses to the service.
type TokenBucketRedis struct {
cli *redis.Client
cli redis.UniversalClient
prefix string
ttl time.Duration
raceCheck bool
Expand All @@ -358,7 +358,7 @@ type TokenBucketRedis struct {
// If raceCheck is true and the keys in Redis are modified in between State() and SetState() calls then
// ErrRaceCondition is returned.
// This adds an extra overhead since a Lua script has to be executed on the Redis side which locks the entire database.
func NewTokenBucketRedis(cli *redis.Client, prefix string, ttl time.Duration, raceCheck bool) *TokenBucketRedis {
func NewTokenBucketRedis(cli redis.UniversalClient, prefix string, ttl time.Duration, raceCheck bool) *TokenBucketRedis {
return &TokenBucketRedis{cli: cli, prefix: prefix, ttl: ttl, raceCheck: raceCheck}
}

Expand Down

0 comments on commit 5fbdd3c

Please sign in to comment.