pub struct DistributedRateLimiterState {
pub key: String,
pub config: RateLimitConfig,
pub fallback: Arc<RwLock<TokenBucket>>,
}Expand description
Distributed rate limiter state
Stores rate limiting state in a distributed backend (e.g., Redis) for coordination across multiple workers.
Fields§
§key: StringRedis key for storing rate limit state
config: RateLimitConfigRate limit configuration
fallback: Arc<RwLock<TokenBucket>>Local fallback limiter (used if distributed backend is unavailable)
Implementations§
Source§impl DistributedRateLimiterState
impl DistributedRateLimiterState
Sourcepub fn new(key: String, config: RateLimitConfig) -> Self
pub fn new(key: String, config: RateLimitConfig) -> Self
Create a new distributed rate limiter state
§Arguments
key- Redis key for storing rate limit stateconfig- Rate limit configuration
Sourcepub fn token_key(&self) -> String
pub fn token_key(&self) -> String
Get the Redis key for token count
Used by backend implementations to store token count.
Sourcepub fn refill_key(&self) -> String
pub fn refill_key(&self) -> String
Get the Redis key for last refill timestamp
Used by backend implementations to store last refill time.
Sourcepub fn window_key(&self) -> String
pub fn window_key(&self) -> String
Get the Redis key for sliding window
Used by backend implementations to store sliding window data.
Trait Implementations§
Source§impl Clone for DistributedRateLimiterState
impl Clone for DistributedRateLimiterState
Source§fn clone(&self) -> DistributedRateLimiterState
fn clone(&self) -> DistributedRateLimiterState
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for DistributedRateLimiterState
impl RefUnwindSafe for DistributedRateLimiterState
impl Send for DistributedRateLimiterState
impl Sync for DistributedRateLimiterState
impl Unpin for DistributedRateLimiterState
impl UnwindSafe for DistributedRateLimiterState
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