pub struct RedisRateLimiter<T> { /* private fields */ }
Expand description
A service that executes quotas and checks for rate limits in a shared cache.
Quotas handle tracking a project’s usage and respond whether a project has been configured to throttle incoming data if they go beyond the specified quota.
Quotas can specify a window to be tracked in, such as per minute or per hour. Additionally,
quotas allow to specify the data categories they apply to, for example error events or
attachments. For more information on quota parameters, see Quota
.
Requires the redis
feature.
Implementations§
Source§impl<T: GlobalLimiter> RedisRateLimiter<T>
impl<T: GlobalLimiter> RedisRateLimiter<T>
Sourcepub fn new(client: AsyncRedisClient, global_limiter: T) -> Self
pub fn new(client: AsyncRedisClient, global_limiter: T) -> Self
Creates a new RedisRateLimiter
instance.
Sourcepub fn max_limit(self, max_limit: Option<u64>) -> Self
pub fn max_limit(self, max_limit: Option<u64>) -> Self
Sets the maximum rate limit in seconds.
By default, this rate limiter will return rate limits based on the quotas’ window
fields.
If a maximum rate limit is set, the returned rate limit will be bounded by this value.
Sourcepub async fn is_rate_limited<'a>(
&self,
quotas: impl IntoIterator<Item = &'a Quota>,
item_scoping: ItemScoping,
quantity: usize,
over_accept_once: bool,
) -> Result<RateLimits, RateLimitingError>
pub async fn is_rate_limited<'a>( &self, quotas: impl IntoIterator<Item = &'a Quota>, item_scoping: ItemScoping, quantity: usize, over_accept_once: bool, ) -> Result<RateLimits, RateLimitingError>
Checks whether any of the quotas in effect have been exceeded and records consumption.
By invoking this method, the caller signals that data is being ingested and needs to be counted against the quota. This increment happens atomically if none of the quotas have been exceeded. Otherwise, a rate limit is returned and data is not counted against the quotas.
If no key is specified, then only organization-wide and project-wide quotas are checked. If a key is specified, then key-quotas are also checked.
When over_accept_once
is set to true
and the current quota would be exceeded by the
provided quantity
, the data is accepted once and subsequent requests will be rejected
until the quota refreshes.
A quantity
of 0
can be used to check if the quota limit has been reached or exceeded
without incrementing it in the success case. This is useful for checking quotas in a different
data category.
Auto Trait Implementations§
impl<T> Freeze for RedisRateLimiter<T>where
T: Freeze,
impl<T> !RefUnwindSafe for RedisRateLimiter<T>
impl<T> Send for RedisRateLimiter<T>where
T: Send,
impl<T> Sync for RedisRateLimiter<T>where
T: Sync,
impl<T> Unpin for RedisRateLimiter<T>where
T: Unpin,
impl<T> !UnwindSafe for RedisRateLimiter<T>
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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