pub struct RedisRateLimiter { /* 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 or not 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 QuotaConfig
.
Requires the redis
feature.
Implementations§
source§impl RedisRateLimiter
impl RedisRateLimiter
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, this limit is bounded.
sourcepub 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 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 for the given project and project key has been exceeded and records consumption of the quota.
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.
If the current consumed quotas are still under the limit and the current quantity would put
it over the limit, which normaly would return the rejection, setting over_accept_once
to true
will allow accept the incoming data even if the limit is exceeded once.
The passed quantity
may be 0
. In this case, the rate limiter will check if the quota
limit has been reached or exceeded without incrementing it in the success case. This can be
useful to check for required quotas in a different data category.
Auto Trait Implementations§
impl !Freeze for RedisRateLimiter
impl !RefUnwindSafe for RedisRateLimiter
impl Send for RedisRateLimiter
impl Sync for RedisRateLimiter
impl Unpin for RedisRateLimiter
impl !UnwindSafe 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
§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