pub struct RedisCache { /* private fields */ }Expand description
Redis cache store.
Implementations§
Source§impl RedisCache
impl RedisCache
Sourcepub async fn new(config: CacheConfig) -> CacheResult<Self>
pub async fn new(config: CacheConfig) -> CacheResult<Self>
Sourcepub fn connection(&self) -> &ConnectionManager
pub fn connection(&self) -> &ConnectionManager
Get the underlying connection manager.
Trait Implementations§
Source§impl CacheStore for RedisCache
impl CacheStore for RedisCache
Source§fn set_json_forever<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: String,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_json_forever<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: String,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Plain SET with no expiry, skipping the default_ttl fallback that
set_json applies to a None TTL. See CacheStore::set_json_forever.
Source§fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Clear this cache’s keys.
When key_prefix is configured, this is scoped to that prefix: it
SCANs for every key matching {key_prefix}:* and removes them with
batched UNLINK calls, so it only wipes keys this cache actually
wrote — not the whole Redis database/instance. SCAN is cursor-based
and non-blocking (unlike KEYS, which is O(N) and stalls the
single-threaded server for the entire keyspace); UNLINK reclaims
memory off the main thread instead of blocking on DEL.
When no key_prefix is configured, this cache has no distinct slice
of the keyspace to scope to, so it falls back to the previous
unscoped FLUSHDB behavior — this remains destructive to the entire
Redis database/instance, so an unprefixed RedisCache sharing a
Redis instance with other services/tenants should not call clear().
Source§fn mget<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<Option<String>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn mget<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<Option<String>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Native multi-get: a single MGET round-trip instead of N GETs.
MGET preserves argument order, so the returned vector matches keys
element-for-element, with None for missing keys.
Source§fn mset<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
items: &'life1 [(&'life2 str, String)],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn mset<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
items: &'life1 [(&'life2 str, String)],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Native multi-set in a single round-trip.
Without a TTL this is a plain MSET. MSET cannot express per-key
expiry, so when a TTL applies we pipeline SET ... EX commands (still
one round-trip), preserving the exact per-key TTL semantics of
set_json (including the default_ttl fallback).
Source§fn mdel<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn mdel<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Native multi-delete: a single variadic DEL round-trip instead of N.
Source§fn supports_atomic_sets(&self) -> bool
fn supports_atomic_sets(&self) -> bool
RedisCache backs set_add/set_remove/set_members with native
SADD/SREM/SMEMBERS, which are atomic — see CacheStore::supports_atomic_sets.
Source§fn set_add<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
member: &'life2 str,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn set_add<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
member: &'life2 str,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Native SADD: atomically adds member to a Redis Set, unlike the
trait default’s non-atomic get/modify/set. This is what makes
crate::invalidation::TaggedCache’s tag index safe to update
concurrently from multiple instances sharing this backend.
Source§fn set_remove<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
member: &'life2 str,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn set_remove<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
member: &'life2 str,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Native SREM: atomically removes member from a Redis Set.
Source§fn set_add_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
members: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn set_add_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
members: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Variadic SADD key m1 m2 ...: one round-trip for the whole batch
rather than one per member.
Source§fn set_remove_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
members: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn set_remove_many<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
members: &'life2 [&'life3 str],
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Variadic SREM key m1 m2 ...: one round-trip for the whole batch.
Source§fn set_members<'life0, 'life1, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_members<'life0, 'life1, 'async_trait>(
&'life0 self,
set_key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Native SMEMBERS.
Source§fn get_json<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_json<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<String>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn set_json<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: String,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_json<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: String,
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn delete<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + 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 = CacheResult<()>> + 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 = CacheResult<bool>> + 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 = CacheResult<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = CacheResult<Option<Duration>>> + 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 = CacheResult<Option<Duration>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn expire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn expire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn increment<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
delta: i64,
) -> Pin<Box<dyn Future<Output = CacheResult<i64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn increment<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
delta: i64,
) -> Pin<Box<dyn Future<Output = CacheResult<i64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn decrement<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
delta: i64,
) -> Pin<Box<dyn Future<Output = CacheResult<i64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn decrement<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
delta: i64,
) -> Pin<Box<dyn Future<Output = CacheResult<i64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn get_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<Option<String>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<Option<String>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn set_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
items: &'life1 [(&'life2 str, String)],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn set_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
items: &'life1 [(&'life2 str, String)],
ttl: Option<Duration>,
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn delete_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn delete_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn exists_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<bool>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn exists_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<bool>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§fn ttl_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<Option<Duration>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn ttl_many<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
keys: &'life1 [&'life2 str],
) -> Pin<Box<dyn Future<Output = CacheResult<Vec<Option<Duration>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Source§impl Clone for RedisCache
impl Clone for RedisCache
Source§fn clone(&self) -> RedisCache
fn clone(&self) -> RedisCache
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more