Documentation
¶
Overview ¶
Package redislimit is a ratelimit.Limiter whose windows live in Redis, so every replica shares them.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is a Redis-backed fixed-window limiter.
func New ¶
func New(c redis.UniversalClient, opts ...Option) *Limiter
New returns a limiter on c. Windows are aligned to the clock of the replica that charges them, so keep replica clocks in sync.
func (*Limiter) Allow ¶
func (l *Limiter) Allow(ctx context.Context, key string, n, limit int64, window time.Duration) (ratelimit.Decision, error)
Allow charges n against key's current fixed window of the given size. If window is <= 0 or n is < 0, it returns a zero Decision and an error, as the memory limiter does. A Redis failure is returned as an error too.
Click to show internal directories.
Click to hide internal directories.