pub struct RedisStore { /* private fields */ }Expand description
A cache backed by Redis.
Cloning shares one pool, so this can be registered as application state.
Implementations§
Source§impl RedisStore
impl RedisStore
Sourcepub fn connect(url: &str) -> Result<Self>
pub fn connect(url: &str) -> Result<Self>
Build a store from a URL: redis://[:password@]host:port[/db].
pub fn new(config: RedisConfig, prefix: impl Into<String>) -> Self
pub fn pool(&self) -> &Pool
Sourcepub async fn verify(&self) -> Result<()>
pub async fn verify(&self) -> Result<()>
Open a connection now, so a bad URL or a wrong password surfaces at boot.
Sourcepub async fn ping(&self) -> Result<String>
pub async fn ping(&self) -> Result<String>
PING. Returns PONG, and is the cheapest liveness check there is.
Sourcepub async fn expire(&self, key: &str, seconds: u64) -> Result<bool>
pub async fn expire(&self, key: &str, seconds: u64) -> Result<bool>
EXPIRE key seconds — whole-second precision, which is what the Redis
command itself offers. Returns whether the key existed.
Trait Implementations§
Source§impl Cache for RedisStore
impl Cache for RedisStore
Source§fn driver(&self) -> &'static str
fn driver(&self) -> &'static str
The driver’s name, used in
cache.hit / cache.miss events and in
error messages. Telescope shows it as the store column.Source§fn get<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Json>>>
fn get<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Json>>>
Fetch a value, or
None when it is missing or expired. Read moreSource§fn put<'a>(
&'a self,
key: &'a str,
value: Json,
ttl: Duration,
) -> BoxFuture<'a, Result<()>>
fn put<'a>( &'a self, key: &'a str, value: Json, ttl: Duration, ) -> BoxFuture<'a, Result<()>>
Store a value that expires after
ttl. Read moreSource§fn forever<'a>(&'a self, key: &'a str, value: Json) -> BoxFuture<'a, Result<()>>
fn forever<'a>(&'a self, key: &'a str, value: Json) -> BoxFuture<'a, Result<()>>
Store a value with no expiry. It still goes away on
Cache::flush.Source§fn forget<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>
fn forget<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>
Remove a key. Returns whether something was actually there.
Source§fn has<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>
fn has<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<bool>>
Whether a live (unexpired) value exists.
Source§fn increment<'a>(&'a self, key: &'a str, by: i64) -> BoxFuture<'a, Result<i64>>
fn increment<'a>(&'a self, key: &'a str, by: i64) -> BoxFuture<'a, Result<i64>>
Add
by to a counter, creating it at zero first. Returns the new value. Read moreSource§fn decrement<'a>(&'a self, key: &'a str, by: i64) -> BoxFuture<'a, Result<i64>>
fn decrement<'a>(&'a self, key: &'a str, by: i64) -> BoxFuture<'a, Result<i64>>
Subtract
by from a counter. Returns the new value.Source§fn increment_within<'a>(
&'a self,
key: &'a str,
by: i64,
ttl: Duration,
) -> BoxFuture<'a, Result<i64>>
fn increment_within<'a>( &'a self, key: &'a str, by: i64, ttl: Duration, ) -> BoxFuture<'a, Result<i64>>
Increment a counter, giving it
ttl only when this call created it. Read moreSource§impl Clone for RedisStore
impl Clone for RedisStore
Source§fn clone(&self) -> RedisStore
fn clone(&self) -> RedisStore
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 !RefUnwindSafe for RedisStore
impl !UnwindSafe for RedisStore
impl Freeze for RedisStore
impl Send for RedisStore
impl Sync for RedisStore
impl Unpin for RedisStore
impl UnsafeUnpin for RedisStore
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