Struct RedisRateLimiter

Source
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>

Source

pub fn new(client: AsyncRedisClient, global_limiter: T) -> Self

Creates a new RedisRateLimiter instance.

Source

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.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T