pub struct RedisRateLimiter { /* private fields */ }Expand description
RateLimiter over Redis: each allowed request ZADDs now into the
key’s sorted set; a request is allowed while the set holds fewer than
limit members within the trailing window.
§Differences from the Workers Rate Limiting binding (documented,
not papered over)
| Workers Rate Limiting binding | RedisRateLimiter | |
|---|---|---|
| Algorithm | fixed-window counter (limit + period per binding, configured in wrangler.toml) | sliding window: a request at the window’s edge does not get a fresh full budget immediately |
retry_after | the binding exposes none — the port’s Decision::retry_after is always None on Workers | Some: milliseconds until the oldest counted request exits the window, so callers can send an honest Retry-After |
| Where the limit lives | the binding declaration (per Worker) | config keys RATE_LIMIT_MAX / RATE_LIMIT_PERIOD_SECS, one budget shared by every module — the same “one venture, one budget per subject” the shared binding gives |
| Scope | counters are per-Cloudflare-edge | one Redis: exact across every process and replica that shares it, and a single point of failure |
| Key space | the binding’s own | rl:-prefixed in the database shared with RedisKv |
Duration-granularity windows are kept whole: the script works in
milliseconds.
Implementations§
Source§impl RedisRateLimiter
impl RedisRateLimiter
pub fn new(conn: ConnectionManager, limit: u64, window: Duration) -> Self
Sourcepub fn from_env(conn: ConnectionManager, config: &dyn Config) -> Self
pub fn from_env(conn: ConnectionManager, config: &dyn Config) -> Self
RATE_LIMIT_MAX (default 100) and RATE_LIMIT_PERIOD_SECS
(default 60) from config.
Trait Implementations§
Source§impl RateLimiter for RedisRateLimiter
impl RateLimiter for RedisRateLimiter
Auto Trait Implementations§
impl !Freeze for RedisRateLimiter
impl !RefUnwindSafe for RedisRateLimiter
impl !UnwindSafe for RedisRateLimiter
impl Send for RedisRateLimiter
impl Sync for RedisRateLimiter
impl Unpin for RedisRateLimiter
impl UnsafeUnpin for RedisRateLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more