Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limiter ¶
type Limiter interface { // Allow reports whether an event with the given token can happen // within the configured maximum rate. Returned is the current // event count and whether the event can happen. Allow(token string) (count int64, ok bool) }
Limiter is an interface implemented by all rate limiting schemes.
type Sliding ¶
type Sliding struct { // WindowDuration defines the width of the sliding window // where events are counted against the maximum. WindowDuration time.Duration // WindowMaximum is the maximum number of events that can // happen within the configured window. WindowMaximum int64 // Redis is the storage backend for per-token rate limit counts. Redis redis.Cmdable // RedisPrefix will prefix all keys used by the Sliding limiter. RedisPrefix string }
Sliding implements a Redis-backed Limiter for a sliding window.
The sliding window is implemented using Redis sorted sets, where each event is a new entry in the sorted set with its timestamp as a score. Events older than the window are evicted and the set eventually expires.
Click to show internal directories.
Click to hide internal directories.