Documentation
¶
Overview ¶
Package ratelimit provides a Redis-backed sliding-window rate limiter with a local in-memory fallback when Redis is unavailable (Lite / single-instance).
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 enforces per-key sliding-window limits. max is evaluated per Allow call so callers (e.g. embed channels) can vary budgets without rebuilding the limiter.
func New ¶
func New(redisClient *redis.Client, keyPrefix string, window time.Duration, instanceID string) *Limiter
New constructs a limiter. keyPrefix should include a trailing delimiter (e.g. "embed:ratelimit:"). When redis is nil, only the local fallback runs.
func (*Limiter) StartCleanup ¶
func (l *Limiter) StartCleanup(stopCh <-chan struct{})
StartCleanup runs periodic eviction for the local fallback map. No-op when only Redis is in use, but cheap to call either way.
Click to show internal directories.
Click to hide internal directories.