pub struct RedisCache<T> { /* private fields */ }Expand description
Redis cache layer for distributed caching
Implementations§
Source§impl<T> RedisCache<T>
impl<T> RedisCache<T>
Sourcepub fn new(pool: Arc<RedisPool>, config: DualCacheConfig) -> Self
pub fn new(pool: Arc<RedisPool>, config: DualCacheConfig) -> Self
Create a new Redis cache with the given pool and configuration
Sourcepub fn with_stats(
pool: Arc<RedisPool>,
config: DualCacheConfig,
stats: Arc<AtomicCacheStats>,
) -> Self
pub fn with_stats( pool: Arc<RedisPool>, config: DualCacheConfig, stats: Arc<AtomicCacheStats>, ) -> Self
Create with shared statistics
Sourcepub async fn get_entry(&self, key: &CacheKey) -> Result<Option<CacheEntry<T>>>
pub async fn get_entry(&self, key: &CacheKey) -> Result<Option<CacheEntry<T>>>
Get an entry with metadata from the cache
Sourcepub async fn set(&self, key: CacheKey, value: T) -> Result<()>
pub async fn set(&self, key: CacheKey, value: T) -> Result<()>
Set a value in the cache with the default TTL
Sourcepub async fn set_with_ttl(
&self,
key: CacheKey,
value: T,
ttl: Duration,
) -> Result<()>
pub async fn set_with_ttl( &self, key: CacheKey, value: T, ttl: Duration, ) -> Result<()>
Set a value in the cache with a specific TTL
Sourcepub async fn set_with_size(
&self,
key: CacheKey,
value: T,
ttl: Duration,
size_bytes: usize,
) -> Result<()>
pub async fn set_with_size( &self, key: CacheKey, value: T, ttl: Duration, size_bytes: usize, ) -> Result<()>
Set a value with size tracking
Sourcepub async fn set_entry(&self, key: CacheKey, entry: CacheEntry<T>) -> Result<()>
pub async fn set_entry(&self, key: CacheKey, entry: CacheEntry<T>) -> Result<()>
Set a cache entry directly
Sourcepub async fn delete_if<F>(
&self,
key: &CacheKey,
predicate: F,
) -> Result<Option<T>>
pub async fn delete_if<F>( &self, key: &CacheKey, predicate: F, ) -> Result<Option<T>>
Delete only while the live Redis value still satisfies predicate.
Reads the raw blob, checks the deserialized value, then CAS-deletes with Lua so a concurrent replacement is not removed. A CAS miss is re-read and retried: an in-flight rewrite of still-matching poison changes the serialized blob and would otherwise return false while L2 stays poisoned (Dual can then report success after an L1-only delete). Returns the deleted value when a matching live entry was removed.
Sourcepub async fn ttl(&self, key: &CacheKey) -> Result<Option<Duration>>
pub async fn ttl(&self, key: &CacheKey) -> Result<Option<Duration>>
Get the remaining TTL for a key
Sourcepub fn stats(&self) -> Arc<AtomicCacheStats> ⓘ
pub fn stats(&self) -> Arc<AtomicCacheStats> ⓘ
Get cache statistics
Sourcepub async fn is_available(&self) -> bool
pub async fn is_available(&self) -> bool
Check if Redis is available
Sourcepub async fn health_check(&self) -> Result<()>
pub async fn health_check(&self) -> Result<()>
Perform a health check
Source§impl<T> RedisCache<T>
Batch operations for Redis cache
impl<T> RedisCache<T>
Batch operations for Redis cache
Sourcepub async fn get_many(&self, keys: &[CacheKey]) -> Result<Vec<Option<T>>>
pub async fn get_many(&self, keys: &[CacheKey]) -> Result<Vec<Option<T>>>
Get multiple values from the cache using Redis MGET
Sourcepub async fn set_many(&self, entries: &[(CacheKey, T, Duration)]) -> Result<()>
pub async fn set_many(&self, entries: &[(CacheKey, T, Duration)]) -> Result<()>
Set multiple values in the cache
Sourcepub async fn delete_many(&self, keys: &[CacheKey]) -> Result<usize>
pub async fn delete_many(&self, keys: &[CacheKey]) -> Result<usize>
Delete multiple keys from the cache
Auto Trait Implementations§
impl<T> !RefUnwindSafe for RedisCache<T>
impl<T> !UnwindSafe for RedisCache<T>
impl<T> Freeze for RedisCache<T>where
PhantomData<T>: Freeze,
impl<T> Send for RedisCache<T>where
PhantomData<T>: Send,
impl<T> Sync for RedisCache<T>where
PhantomData<T>: Sync,
impl<T> Unpin for RedisCache<T>where
PhantomData<T>: Unpin,
impl<T> UnsafeUnpin for RedisCache<T>where
PhantomData<T>: UnsafeUnpin,
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> BudgetAwareRouting for T
impl<T> BudgetAwareRouting for T
Source§fn filter_by_budget(
&self,
providers: Vec<String>,
budget_router: &BudgetAwareRouter,
) -> Vec<String>
fn filter_by_budget( &self, providers: Vec<String>, budget_router: &BudgetAwareRouter, ) -> Vec<String>
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