pub trait Store {
// Required methods
fn compare_and_swap_with_ttl(
&mut self,
key: &str,
old: i64,
new: i64,
ttl: Duration,
) -> Result<bool, CellError>;
fn get_with_time(&self, key: &str) -> Result<(i64, Tm), CellError>;
fn log_debug(&self, message: &str);
fn set_if_not_exists_with_ttl(
&mut self,
key: &str,
value: i64,
ttl: Duration,
) -> Result<bool, CellError>;
}
Expand description
Store exposes the atomic data store operations that the GCRA rate limiter needs to function correctly.
Note that because the default mode for this library is to run within Redis (making every operation atomic by default), the encapsulation is not strictly needed. However, it’s written to be generic enough that a out-of-Redis Store could be written and have the rate limiter still work properly.
Required Methods§
Sourcefn compare_and_swap_with_ttl(
&mut self,
key: &str,
old: i64,
new: i64,
ttl: Duration,
) -> Result<bool, CellError>
fn compare_and_swap_with_ttl( &mut self, key: &str, old: i64, new: i64, ttl: Duration, ) -> Result<bool, CellError>
Compares the value at the given key with a known old value and swaps it for a new value if and only if they’re equal. Also sets the key’s TTL until it expires.
Sourcefn get_with_time(&self, key: &str) -> Result<(i64, Tm), CellError>
fn get_with_time(&self, key: &str) -> Result<(i64, Tm), CellError>
Gets the given key’s value and the current time as dictated by the store (this is done so that rate limiters running on a variety of different nodes can operate with a consistent clock instead of using their own). If the key was unset, -1 is returned.