Documentation
¶
Overview ¶
Package redis implements a distributed rate limiting driver using Redis as the backend. It relies on atomic Redis Lua scripts provided by pluggable algorithm strategies to enforce rate limits consistently across distributed microservices.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver implements the distlimit.Driver interface using Redis as the storage backend. All rate limit operations execute atomically in Redis via algorithm-specific Lua scripts.
Driver is thread-safe and safe for concurrent use by multiple goroutines.
func New ¶
func New(client redis.UniversalClient, opts ...Option) *Driver
New creates and initializes a new Redis-backed rate limiting Driver.
func (*Driver) Allow ¶
func (d *Driver) Allow(ctx context.Context, key string, limit int64, window time.Duration, alg algorithm.Algorithm) (algorithm.Result, error)
Allow evaluates the rate limit for a key using the Lua script provided by the algorithm strategy. It sends evaluation parameters (limit, window, current timestamp) to Redis and parses the response.
type Option ¶
type Option func(*Driver)
Option configures functional parameters for the Redis Driver.
func WithPrefix ¶
WithPrefix sets a custom key prefix for all rate limit keys stored in Redis. This is useful for namespacing and avoiding key collisions across environments or services. The default prefix is "distlimit".