pub struct L2Cache { /* private fields */ }Expand description
L2 Cache using Redis with ConnectionManager for automatic reconnection
Implementations§
Source§impl L2Cache
impl L2Cache
Sourcepub async fn new() -> Result<Self>
pub async fn new() -> Result<Self>
Create new L2 cache with ConnectionManager for automatic reconnection
Sourcepub async fn get(&self, key: &str) -> Option<Value>
pub async fn get(&self, key: &str) -> Option<Value>
Get value from L2 cache using persistent ConnectionManager
Sourcepub async fn get_with_ttl(&self, key: &str) -> Option<(Value, Option<Duration>)>
pub async fn get_with_ttl(&self, key: &str) -> Option<(Value, Option<Duration>)>
Get value with its remaining TTL from L2 cache
Returns tuple of (value, ttl_seconds) if key exists TTL is in seconds, None if key doesn’t exist or has no expiration
Sourcepub async fn set_with_ttl(
&self,
key: &str,
value: Value,
ttl: Duration,
) -> Result<()>
pub async fn set_with_ttl( &self, key: &str, value: Value, ttl: Duration, ) -> Result<()>
Set value with custom TTL using persistent ConnectionManager
Sourcepub async fn remove(&self, key: &str) -> Result<()>
pub async fn remove(&self, key: &str) -> Result<()>
Remove value from cache using persistent ConnectionManager
Sourcepub async fn health_check(&self) -> bool
pub async fn health_check(&self) -> bool
Health check
Sourcepub async fn stream_add(
&self,
stream_key: &str,
fields: Vec<(String, String)>,
maxlen: Option<usize>,
) -> Result<String>
pub async fn stream_add( &self, stream_key: &str, fields: Vec<(String, String)>, maxlen: Option<usize>, ) -> Result<String>
Publish data to Redis Stream using XADD
§Arguments
stream_key- Name of the Redis Stream (e.g., “events_stream”)fields- Vec of field-value pairs to add to the streammaxlen- Optional maximum length for stream trimming (uses MAXLEN ~ for approximate trimming)
§Returns
The stream entry ID generated by Redis (e.g., “1234567890123-0”)
Sourcepub async fn stream_read_latest(
&self,
stream_key: &str,
count: usize,
) -> Result<Vec<(String, Vec<(String, String)>)>>
pub async fn stream_read_latest( &self, stream_key: &str, count: usize, ) -> Result<Vec<(String, Vec<(String, String)>)>>
Sourcepub async fn stream_read(
&self,
stream_key: &str,
last_id: &str,
count: usize,
block_ms: Option<usize>,
) -> Result<Vec<(String, Vec<(String, String)>)>>
pub async fn stream_read( &self, stream_key: &str, last_id: &str, count: usize, block_ms: Option<usize>, ) -> Result<Vec<(String, Vec<(String, String)>)>>
Read entries from Redis Stream using XREAD (blocking or non-blocking)
§Arguments
stream_key- Name of the Redis Streamlast_id- Last entry ID seen (use “0” to read from beginning, “$” for only new entries)count- Maximum number of entries to retrieveblock_ms- Optional blocking timeout in milliseconds (None for non-blocking)
§Returns
Vector of (entry_id, fields) tuples
Trait Implementations§
Source§impl CacheBackend for L2Cache
Implement CacheBackend trait for L2Cache
impl CacheBackend for L2Cache
Implement CacheBackend trait for L2Cache
This allows L2Cache 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 L2Cache
Implement L2CacheBackend trait for L2Cache
impl L2CacheBackend for L2Cache
Implement L2CacheBackend trait for L2Cache
This extends CacheBackend with TTL introspection capabilities needed for L2->L1 promotion.
Source§fn get_with_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<(Value, Option<Duration>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_with_ttl<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Option<(Value, Option<Duration>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§impl StreamingBackend for L2Cache
Implement StreamingBackend trait for L2Cache
impl StreamingBackend for L2Cache
Implement StreamingBackend trait for L2Cache
This enables Redis Streams functionality for event-driven architectures.