pub struct RedisBackend { /* private fields */ }Expand description
Redis backend powered by the fred client.
Call connect before issuing any cache operations.
Implementations§
Source§impl RedisBackend
impl RedisBackend
Sourcepub fn builder() -> RedisBackendBuilder
pub fn builder() -> RedisBackendBuilder
Start building a RedisBackend.
Sourcepub async fn connect(&self) -> Result<ConnectHandle, BackendError>
pub async fn connect(&self) -> Result<ConnectHandle, BackendError>
Connect to Redis and wait until the connection is established.
This must be called before any cache operations.
The returned ConnectHandle is fred’s handle to the spawned task that
drives the connection (a tokio JoinHandle). Dropping it detaches the
task without stopping it: the connection, and any auto-reconnect,
keeps running for as long as the backend is alive. The intent presets
drop it for that reason. Keep it only to observe how the connection
ended: the task resolves when the connection closes for good (on a
fail-fast backend, the first dropped connection), with the error that
closed it, if any. Do not abort it while the backend is still in use.
Trait Implementations§
Source§impl Backend for RedisBackend
impl Backend for RedisBackend
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<u8>>, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
key, or None if absent.Source§fn set<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Vec<u8>,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Vec<u8>,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<(), BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
value under key, optionally expiring after ttl.Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn exists<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
true if key exists without fetching the value.Source§fn health<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<HealthStatus, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn health<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<HealthStatus, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn as_lockable(&self) -> Option<&dyn LockableBackend>
fn as_lockable(&self) -> Option<&dyn LockableBackend>
LockableBackend capability, if it has one. Read moreSource§fn attach_metrics(&self, _provider: MetricsProvider)
fn attach_metrics(&self, _provider: MetricsProvider)
Source§impl Debug for RedisBackend
impl Debug for RedisBackend
Source§impl LockableBackend for RedisBackend
impl LockableBackend for RedisBackend
Source§fn acquire_lock<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
timeout_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn acquire_lock<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
timeout_ms: u64,
) -> Pin<Box<dyn Future<Output = Result<Option<String>, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn release_lock<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
lock_id: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn release_lock<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
key: &'life1 str,
lock_id: &'life2 str,
) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
lock_id still owns the lock: a late or duplicate release
must never free a lock acquired since. Return Ok(false) when
lock_id no longer owns the lock; Err only when the outcome is
unknown. The single-flight takes Ok as answered and never re-sends
it, and re-sends after an Err on the key’s next lock attempt.Source§impl TtlInspectable for RedisBackend
impl TtlInspectable for RedisBackend
Source§fn ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Duration>, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Duration>, BackendError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
key, or None if the key does not exist
or has no expiry.Source§fn refresh_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
_key: &'life1 str,
_ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn refresh_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
_key: &'life1 str,
_ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<bool, BackendError>> + Send + 'async_trait>>where
Self: Sync + 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !RefUnwindSafe for RedisBackend
impl !UnwindSafe for RedisBackend
impl Freeze for RedisBackend
impl Send for RedisBackend
impl Sync for RedisBackend
impl Unpin for RedisBackend
impl UnsafeUnpin for RedisBackend
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more