pub struct RedisBackend<C: RedisClient> { /* private fields */ }Available on crate feature
distributed-rate-limit only.Expand description
Redis backend adapter.
§Examples
use http_handle::distributed_rate_limit::{RedisBackend, RedisClient};
use http_handle::ServerError;
#[derive(Debug)]
struct Dummy;
impl RedisClient for Dummy {
fn incr_with_ttl(&self, _key: &str, _ttl_secs: u64) -> Result<u64, ServerError> { Ok(1) }
}
let _backend = RedisBackend::new(Dummy);
assert_eq!(1, 1);§Panics
This type does not panic.
Implementations§
Source§impl<C: RedisClient> RedisBackend<C>
impl<C: RedisClient> RedisBackend<C>
Sourcepub fn new(client: C) -> Self
pub fn new(client: C) -> Self
Creates a new Redis backend adapter.
§Examples
use http_handle::distributed_rate_limit::{RedisBackend, RedisClient};
use http_handle::ServerError;
#[derive(Debug)]
struct Dummy;
impl RedisClient for Dummy {
fn incr_with_ttl(&self, _key: &str, _ttl_secs: u64) -> Result<u64, ServerError> { Ok(1) }
}
let _backend = RedisBackend::new(Dummy);
assert_eq!(1, 1);§Panics
This function does not panic.
Trait Implementations§
Source§impl<C: Debug + RedisClient> Debug for RedisBackend<C>
impl<C: Debug + RedisClient> Debug for RedisBackend<C>
Source§impl<C: RedisClient> RateLimitBackend for RedisBackend<C>
impl<C: RedisClient> RateLimitBackend for RedisBackend<C>
Source§fn increment_and_get(
&self,
key: &str,
window_secs: u64,
) -> Result<u64, ServerError>
fn increment_and_get( &self, key: &str, window_secs: u64, ) -> Result<u64, ServerError>
Increments key and returns current hit count for the active window.
Auto Trait Implementations§
impl<C> Freeze for RedisBackend<C>where
C: Freeze,
impl<C> RefUnwindSafe for RedisBackend<C>where
C: RefUnwindSafe,
impl<C> Send for RedisBackend<C>
impl<C> Sync for RedisBackend<C>
impl<C> Unpin for RedisBackend<C>where
C: Unpin,
impl<C> UnsafeUnpin for RedisBackend<C>where
C: UnsafeUnpin,
impl<C> UnwindSafe for RedisBackend<C>where
C: UnwindSafe,
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