Documentation
¶
Overview ¶
Package memcachedstore provides a memcached-backed ratelimit.Store (token-bucket) built on the native celeris driver/memcached client. Drop-in rival to middleware/ratelimit/redisstore for deployments that prefer memcached.
Memcached does not support server-side scripting (no Lua EVALSHA), so the atomic token-bucket update is implemented via a CAS loop: Gets retrieves state + CAS token, the client computes new state, then CAS writes it back. On CAS conflict (another goroutine won the race) we retry up to [maxCASRetries] times. In the uncontended common case this is a single Gets + CAS round trip.
Atomicity is per-key: each key's bucket is updated atomically via its own CAS loop. 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 per second. Required (> 0).
RPS float64
// Burst is the bucket capacity. Required (> 0).
Burst int
// TTL is the memcached expiry applied to each bucket key.
// Default: 2 * (Burst / RPS), minimum 1 minute.
TTL time.Duration
}
Options configure the memcached-backed rate limit store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store implements ratelimit.Store and ratelimit.StoreUndo.
func (*Store) Allow ¶
Allow implements ratelimit.Store.
func (*Store) RetriesTotal ¶
RetriesTotal returns the number of CAS retries observed since construction. Useful for monitoring contention.