Documentation
¶
Overview ¶
Package ratelimit provides fixed-window counters shared by all API replicas through Redis, with an in-memory fallback when Redis is not configured or temporarily unreachable.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Counter ¶
type Counter interface {
// Hit records one event for key and returns the count in the current
// window and the time until the window resets.
Hit(ctx context.Context, key string, window time.Duration) (count int64, reset time.Duration, err error)
// Count returns the current count without recording an event.
Count(ctx context.Context, key string) (count int64, reset time.Duration, err error)
// Reset clears key.
Reset(ctx context.Context, key string) error
}
Counter counts events per key in fixed time windows.
type Fallback ¶
type Fallback struct {
Primary, Secondary Counter
// contains filtered or unexported fields
}
Fallback uses primary and switches to secondary for any call where primary fails, so a Redis outage degrades limits to per-replica instead of disabling them or blocking logins.
type Memory ¶
type Memory struct {
// contains filtered or unexported fields
}
Memory is a per-process Counter. It is correct for a single replica and is used as a fallback when Redis fails.