Skip to main content

InMemoryBackend

Struct InMemoryBackend 

Source
pub struct InMemoryBackend { /* private fields */ }
Expand description

内存后端(模拟 Redis)

使用 RwLock<HashMap> 存储计数器,模拟 Redis 的 INCR + EXPIRE 行为。 适用于单机场景和测试,不适用于真正的分布式环境。

Implementations§

Source§

impl InMemoryBackend

Source

pub fn new() -> Self

Trait Implementations§

Source§

impl Default for InMemoryBackend

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl DistributedBackend for InMemoryBackend

Source§

fn incr_and_get( &self, key: &str, window_secs: u64, window_start: i64, _max_requests: u64, ) -> Result<(u64, i64), RateLimitError>

原子递增并返回递增后的值 Read more
Source§

fn get(&self, key: &str) -> Result<Option<(u64, i64)>, RateLimitError>

获取当前计数(不递增)
Source§

fn reset_key(&self, key: &str) -> Result<(), RateLimitError>

重置 key(删除)

Auto Trait Implementations§

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.

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, 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.