pub struct RedisCache { /* private fields */ }Expand description
Redis distributed cache with ConnectionManager for automatic reconnection
This is the default L2 (warm tier) cache backend, providing:
- Distributed caching across multiple instances
- Persistence to disk
- Automatic reconnection via
ConnectionManager - TTL introspection for cache promotion
- Pattern-based key scanning
Implementations§
Source§impl RedisCache
impl RedisCache
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Create new Redis cache with ConnectionManager for automatic reconnection
§Errors
Returns an error if the Redis client cannot be created or connection fails.
Sourcepub async fn scan_keys(&self, pattern: &str) -> Result<Vec<String>>
pub async fn scan_keys(&self, pattern: &str) -> Result<Vec<String>>
Scan keys matching a pattern (glob-style: *, ?, [])
Uses Redis SCAN command (non-blocking, cursor-based iteration) This is safe for production use, unlike KEYS command.
§Arguments
pattern- Glob-style pattern (e.g., “user:”, “product:123:”)
§Returns
Vector of matching key names
§Examples
// Find all user cache keys
let keys = cache.scan_keys("user:*").await?;
// Find specific user's cache keys
let keys = cache.scan_keys("user:123:*").await?;§Errors
Returns an error if the Redis command fails.
Trait Implementations§
Source§impl CacheBackend for RedisCache
Implement CacheBackend trait for RedisCache
impl CacheBackend for RedisCache
Implement CacheBackend trait for RedisCache
This allows RedisCache to be used as a pluggable backend in the multi-tier cache system.
Source§fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<Value>> + 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 = Option<Value>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn set_with_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Value,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_with_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
value: Value,
ttl: Duration,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl L2CacheBackend for RedisCache
Implement L2CacheBackend trait for RedisCache
impl L2CacheBackend for RedisCache
Implement L2CacheBackend trait for RedisCache
This extends CacheBackend with TTL introspection capabilities needed for L2->L1 promotion.