Documentation
¶
Overview ¶
Package ratelimit admits events per key against one or more sliding windows ("at most Limit in any Per"), in process or shared through Redis (or Garnet). Both stores keep the same log of admitted event times, so a limit and its retry time mean the same thing with and without Redis.
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 admits events from per-key allowances.
func (*Limiter) Allow ¶
Allow admits one event for key, or refuses it (not counting it) with how long until one fits. A Redis error falls back to the per-process log for redisBackoff.
func (*Limiter) AllowMember ¶ added in v0.137.0
AllowMember is Allow counting distinct members: a member key already has in a window is admitted again without counting there, from the time it was first admitted.
type Options ¶
type Options struct {
Windows []Window // an event must fit every one
// Redis shares the log across replicas; nil keeps it per process.
Redis redis.UniversalClient
Prefix string // Redis key prefix
// Errors counts Redis failures; each is served by the per-process log.
Errors *expvar.Int
Logger *slog.Logger
Now func() time.Time // default time.Now
}
Options configure a Limiter.