pub struct RedisCache { /* private fields */ }Expand description
Redis caching operations
Implementations§
Source§impl RedisCache
impl RedisCache
Sourcepub fn new(client: ConnectionManager) -> Self
pub fn new(client: ConnectionManager) -> Self
Create new Redis cache
Sourcepub fn with_prefix(client: ConnectionManager, prefix: impl Into<String>) -> Self
pub fn with_prefix(client: ConnectionManager, prefix: impl Into<String>) -> Self
Create new Redis cache with custom prefix
Sourcepub async fn cache_embedding(
&self,
key: &str,
embedding: &[f32],
) -> MemoryResult<()>
pub async fn cache_embedding( &self, key: &str, embedding: &[f32], ) -> MemoryResult<()>
Cache an embedding vector
Sourcepub async fn get_embedding(&self, key: &str) -> MemoryResult<Option<Vec<f32>>>
pub async fn get_embedding(&self, key: &str) -> MemoryResult<Option<Vec<f32>>>
Get cached embedding
Sourcepub async fn set<T: Serialize>(&self, key: &str, value: &T) -> MemoryResult<()>
pub async fn set<T: Serialize>(&self, key: &str, value: &T) -> MemoryResult<()>
Cache a serializable value with default TTL
Sourcepub async fn set_with_ttl<T: Serialize>(
&self,
key: &str,
value: &T,
ttl_seconds: u64,
) -> MemoryResult<()>
pub async fn set_with_ttl<T: Serialize>( &self, key: &str, value: &T, ttl_seconds: u64, ) -> MemoryResult<()>
Cache a serializable value with custom TTL
Sourcepub async fn get<T: DeserializeOwned>(
&self,
key: &str,
) -> MemoryResult<Option<T>>
pub async fn get<T: DeserializeOwned>( &self, key: &str, ) -> MemoryResult<Option<T>>
Get a cached value
Sourcepub async fn invalidate(&self, key: &str) -> MemoryResult<()>
pub async fn invalidate(&self, key: &str) -> MemoryResult<()>
Invalidate cache key
Sourcepub async fn invalidate_pattern(&self, pattern: &str) -> MemoryResult<u64>
pub async fn invalidate_pattern(&self, pattern: &str) -> MemoryResult<u64>
Invalidate all keys matching a pattern
Sourcepub async fn exists(&self, key: &str) -> MemoryResult<bool>
pub async fn exists(&self, key: &str) -> MemoryResult<bool>
Check if a key exists
Sourcepub async fn expire(&self, key: &str, ttl_seconds: u64) -> MemoryResult<bool>
pub async fn expire(&self, key: &str, ttl_seconds: u64) -> MemoryResult<bool>
Set expiration on an existing key
Sourcepub async fn ttl(&self, key: &str) -> MemoryResult<i64>
pub async fn ttl(&self, key: &str) -> MemoryResult<i64>
Get TTL of a key
Sourcepub async fn incr(&self, key: &str) -> MemoryResult<i64>
pub async fn incr(&self, key: &str) -> MemoryResult<i64>
Increment a counter
Sourcepub async fn set_session<T: Serialize>(
&self,
session_id: &str,
data: &T,
) -> MemoryResult<()>
pub async fn set_session<T: Serialize>( &self, session_id: &str, data: &T, ) -> MemoryResult<()>
Store session data
Sourcepub async fn get_session<T: DeserializeOwned>(
&self,
session_id: &str,
) -> MemoryResult<Option<T>>
pub async fn get_session<T: DeserializeOwned>( &self, session_id: &str, ) -> MemoryResult<Option<T>>
Get session data
Sourcepub async fn extend_session(&self, session_id: &str) -> MemoryResult<bool>
pub async fn extend_session(&self, session_id: &str) -> MemoryResult<bool>
Extend session TTL
Sourcepub async fn delete_session(&self, session_id: &str) -> MemoryResult<()>
pub async fn delete_session(&self, session_id: &str) -> MemoryResult<()>
Delete session
Sourcepub async fn cache_user_memories(
&self,
user_id: &str,
memory_type: &str,
memory_ids: &[String],
) -> MemoryResult<()>
pub async fn cache_user_memories( &self, user_id: &str, memory_type: &str, memory_ids: &[String], ) -> MemoryResult<()>
Cache user memory list
Sourcepub async fn get_user_memories(
&self,
user_id: &str,
memory_type: &str,
) -> MemoryResult<Option<Vec<String>>>
pub async fn get_user_memories( &self, user_id: &str, memory_type: &str, ) -> MemoryResult<Option<Vec<String>>>
Get cached user memory list
Sourcepub async fn invalidate_user_cache(&self, user_id: &str) -> MemoryResult<u64>
pub async fn invalidate_user_cache(&self, user_id: &str) -> MemoryResult<u64>
Invalidate user memory cache
Sourcepub async fn ping(&self) -> MemoryResult<bool>
pub async fn ping(&self) -> MemoryResult<bool>
Ping Redis to check connectivity
Sourcepub async fn info(&self) -> MemoryResult<String>
pub async fn info(&self) -> MemoryResult<String>
Get Redis info
Auto Trait Implementations§
impl Freeze for RedisCache
impl !RefUnwindSafe for RedisCache
impl Send for RedisCache
impl Sync for RedisCache
impl Unpin for RedisCache
impl !UnwindSafe for RedisCache
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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