Skip to main content

RedisStore

Struct RedisStore 

Source
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

Source

pub fn connect(url: &str) -> Result<Self>

Build a store from a URL: redis://[:password@]host:port[/db].

Source

pub fn new(config: RedisConfig, prefix: impl Into<String>) -> Self

Source

pub fn pool(&self) -> &Pool

Source

pub async fn verify(&self) -> Result<()>

Open a connection now, so a bad URL or a wrong password surfaces at boot.

Source

pub async fn ping(&self) -> Result<String>

PING. Returns PONG, and is the cheapest liveness check there is.

Source

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.

Source

pub async fn pexpire(&self, key: &str, ttl: Duration) -> Result<bool>

PEXPIRE key milliseconds, for the sub-second windows a rate limiter wants and EXPIRE cannot express.

Source

pub async fn command(&self, args: &[&[u8]]) -> Result<Value>

Run an arbitrary command. The escape hatch for anything this crate does not wrap; arguments are still length-prefixed, so it cannot be injected.

Trait Implementations§

Source§

impl Cache for RedisStore

Source§

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

Fetch a value, or None when it is missing or expired. Read more
Source§

fn put<'a>( &'a self, key: &'a str, value: Json, ttl: Duration, ) -> BoxFuture<'a, Result<()>>

Store a value that expires after ttl. Read more
Source§

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

Remove a key. Returns whether something was actually there.
Source§

fn flush(&self) -> BoxFuture<'_, Result<()>>

Remove everything this store owns.
Source§

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

Add by to a counter, creating it at zero first. Returns the new value. Read more
Source§

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

Increment a counter, giving it ttl only when this call created it. Read more
Source§

fn ttl<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Duration>>>

How long until a key expires: None when it is missing or immortal. Read more
Source§

fn pull<'a>(&'a self, key: &'a str) -> BoxFuture<'a, Result<Option<Json>>>

Read a value and remove it in one call — Laravel’s Cache::pull.
Source§

impl Clone for RedisStore

Source§

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)

Performs copy-assignment from source. Read more

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> CacheExt for T
where T: Cache + ?Sized,

Source§

fn remember<'a, F, Fut>( &'a self, key: &'a str, ttl: Duration, compute: F, ) -> impl Future<Output = Result<Json>> + Send + 'a
where F: FnOnce() -> Fut + Send + 'a, Fut: Future<Output = Result<Json>> + Send + 'a,

Return the cached value, or compute it, store it for ttl, and return it. Read more
Source§

fn remember_forever<'a, F, Fut>( &'a self, key: &'a str, compute: F, ) -> impl Future<Output = Result<Json>> + Send + 'a
where F: FnOnce() -> Fut + Send + 'a, Fut: Future<Output = Result<Json>> + Send + 'a,

CacheExt::remember with no expiry.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.