Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use redis universal client in token bucket #34

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions concurrent_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ func (c *ConcurrentBufferInMemory) Remove(_ context.Context, key string) error {
// ConcurrentBufferRedis implements ConcurrentBufferBackend in Redis.
type ConcurrentBufferRedis struct {
clock Clock
cli *redis.Client
cli redis.UniversalClient
key string
ttl time.Duration
}

// NewConcurrentBufferRedis creates a new instance of ConcurrentBufferRedis.
// When the TTL of a key exceeds the key is removed from the buffer. This is needed in case if the process that added
// that key to the buffer did not call Done() for some reason.
func NewConcurrentBufferRedis(cli *redis.Client, key string, ttl time.Duration, clock Clock) *ConcurrentBufferRedis {
func NewConcurrentBufferRedis(cli redis.UniversalClient, key string, ttl time.Duration, clock Clock) *ConcurrentBufferRedis {
return &ConcurrentBufferRedis{clock: clock, cli: cli, key: key, ttl: ttl}
}

Expand Down
4 changes: 2 additions & 2 deletions fixedwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ func (f *FixedWindowInMemory) Increment(ctx context.Context, window time.Time, _

// FixedWindowRedis implements FixedWindow in Redis.
type FixedWindowRedis struct {
cli *redis.Client
cli redis.UniversalClient
prefix string
}

// NewFixedWindowRedis returns a new instance of FixedWindowRedis.
// Prefix is the key prefix used to store all the keys used in this implementation in Redis.
func NewFixedWindowRedis(cli *redis.Client, prefix string) *FixedWindowRedis {
func NewFixedWindowRedis(cli redis.UniversalClient, prefix string) *FixedWindowRedis {
return &FixedWindowRedis{cli: cli, prefix: prefix}
}

Expand Down
4 changes: 2 additions & 2 deletions leakybucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ const (

// LeakyBucketRedis is a Redis implementation of a LeakyBucketStateBackend.
type LeakyBucketRedis struct {
cli *redis.Client
cli redis.UniversalClient
prefix string
ttl time.Duration
raceCheck bool
Expand All @@ -285,7 +285,7 @@ type LeakyBucketRedis struct {
//
// If raceCheck is true and the keys in Redis are modified in between State() and SetState() calls then
// ErrRaceCondition is returned.
func NewLeakyBucketRedis(cli *redis.Client, prefix string, ttl time.Duration, raceCheck bool) *LeakyBucketRedis {
func NewLeakyBucketRedis(cli redis.UniversalClient, prefix string, ttl time.Duration, raceCheck bool) *LeakyBucketRedis {
return &LeakyBucketRedis{cli: cli, prefix: prefix, ttl: ttl, raceCheck: raceCheck}
}

Expand Down
2 changes: 1 addition & 1 deletion limiters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (c *fakeClock) reset() {
type LimitersTestSuite struct {
suite.Suite
etcdClient *clientv3.Client
redisClient *redis.Client
redisClient redis.UniversalClient
consulClient *api.Client
zkConn *zk.Conn
logger *l.StdLogger
Expand Down
4 changes: 2 additions & 2 deletions slidingwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ func (s *SlidingWindowInMemory) Increment(ctx context.Context, prev, curr time.T

// SlidingWindowRedis implements SlidingWindow in Redis.
type SlidingWindowRedis struct {
cli *redis.Client
cli redis.UniversalClient
prefix string
}

// NewSlidingWindowRedis creates a new instance of SlidingWindowRedis.
func NewSlidingWindowRedis(cli *redis.Client, prefix string) *SlidingWindowRedis {
func NewSlidingWindowRedis(cli redis.UniversalClient, prefix string) *SlidingWindowRedis {
return &SlidingWindowRedis{cli: cli, prefix: prefix}
}

Expand Down
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
Loading