Documentation
¶
Overview ¶
Package redisstore provides a Redis-backed ratelimit.Store (token-bucket) built on the native celeris driver/redis client.
The token-bucket state is stored as a Redis hash {tokens, last} per key; atomic updates are performed by an embedded Lua script loaded via SCRIPT LOAD at New time. EVALSHA is used on the hot path; on NOSCRIPT (script flushed from server cache) the script is reloaded once and the call is retried.
Atomicity is per-key: a single key's bucket is updated atomically. Cross-key operations are independent.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// KeyPrefix is prepended to every rate limit key. Default: "rl:".
KeyPrefix string
// RPS is the refill rate in tokens/second. Required (> 0).
RPS float64
// Burst is the bucket capacity (maximum tokens). Required (> 0).
Burst int
// TTL is the Redis expiry applied to each bucket key. Default:
// 2 * (Burst / RPS), minimum 1 minute.
TTL time.Duration
}
Options configure the Redis-backed rate limit store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements ratelimit.Store and ratelimit.StoreUndo.
func New ¶
New constructs a Store and preloads the Lua scripts. Returns an error if script loading fails.
func (*Store) Allow ¶
Allow implements ratelimit.Store. A passed key is prefixed with the configured KeyPrefix before hitting Redis.