pub struct RedisBackedRateLimiter { /* private fields */ }Expand description
Redis-shared per-minute limiter: increments rate_limit:{key}:{minute} with a 60s
expiry on first use. Uses the in-memory limiter whenever Redis is unconfigured or fails.
Implementations§
Source§impl RedisBackedRateLimiter
impl RedisBackedRateLimiter
Sourcepub fn new() -> Self
pub fn new() -> Self
Builds a limiter using Redis configuration from the environment when available, otherwise operating on the in-memory fallback only.
Sourcepub fn with_storage(storage: RedisStorage) -> Self
pub fn with_storage(storage: RedisStorage) -> Self
Builds a limiter backed by the given Redis storage plus an in-memory fallback.
Trait Implementations§
Source§impl Default for RedisBackedRateLimiter
impl Default for RedisBackedRateLimiter
Source§impl RateLimiter for RedisBackedRateLimiter
impl RateLimiter for RedisBackedRateLimiter
Source§fn is_allowed<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
limit: u32,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn is_allowed<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
limit: u32,
) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Returns whether
key may proceed under limit requests for the current minute.Auto Trait Implementations§
impl Freeze for RedisBackedRateLimiter
impl RefUnwindSafe for RedisBackedRateLimiter
impl Send for RedisBackedRateLimiter
impl Sync for RedisBackedRateLimiter
impl Unpin for RedisBackedRateLimiter
impl UnsafeUnpin for RedisBackedRateLimiter
impl UnwindSafe for RedisBackedRateLimiter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more