pub struct RedisCache { /* private fields */ }Expand description
Redis cache client with connection management
Implementations§
Source§impl RedisCache
impl RedisCache
Sourcepub async fn new(config: CacheConfig) -> Result<Self>
pub async fn new(config: CacheConfig) -> Result<Self>
Create a new Redis cache connection
Sourcepub async fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
pub async fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>
Get a value from cache
Sourcepub async fn set<T: Serialize>(
&self,
key: &str,
value: &T,
ttl_secs: u64,
) -> Result<()>
pub async fn set<T: Serialize>( &self, key: &str, value: &T, ttl_secs: u64, ) -> Result<()>
Set a value in cache with TTL
Sourcepub async fn set_default<T: Serialize>(
&self,
key: &str,
value: &T,
) -> Result<()>
pub async fn set_default<T: Serialize>( &self, key: &str, value: &T, ) -> Result<()>
Set a value with default TTL
Sourcepub async fn delete_pattern(&self, pattern: &str) -> Result<u64>
pub async fn delete_pattern(&self, pattern: &str) -> Result<u64>
Delete multiple keys matching a pattern
Sourcepub async fn incr_with_expiry(&self, key: &str, ttl_secs: u64) -> Result<i64>
pub async fn incr_with_expiry(&self, key: &str, ttl_secs: u64) -> Result<i64>
Increment with expiry (for rate limiting windows)
Sourcepub async fn try_lock(
&self,
resource: &str,
ttl_secs: u64,
) -> Result<Option<String>>
pub async fn try_lock( &self, resource: &str, ttl_secs: u64, ) -> Result<Option<String>>
Try to acquire a distributed lock
Sourcepub async fn release_lock(&self, resource: &str, lock_id: &str) -> Result<bool>
pub async fn release_lock(&self, resource: &str, lock_id: &str) -> Result<bool>
Release a distributed lock
Sourcepub async fn health_check(&self) -> Result<bool>
pub async fn health_check(&self) -> Result<bool>
Health check
Source§impl RedisCache
User session cache operations
impl RedisCache
User session cache operations
Sourcepub async fn set_session(&self, session_id: &str, user_id: Uuid) -> Result<()>
pub async fn set_session(&self, session_id: &str, user_id: Uuid) -> Result<()>
Cache a user session
Sourcepub async fn get_session(&self, session_id: &str) -> Result<Option<Uuid>>
pub async fn get_session(&self, session_id: &str) -> Result<Option<Uuid>>
Get user ID from session
Sourcepub async fn invalidate_session(&self, session_id: &str) -> Result<bool>
pub async fn invalidate_session(&self, session_id: &str) -> Result<bool>
Invalidate a session
Sourcepub async fn invalidate_user_sessions(&self, user_id: Uuid) -> Result<u64>
pub async fn invalidate_user_sessions(&self, user_id: Uuid) -> Result<u64>
Invalidate all sessions for a user
Source§impl RedisCache
User profile cache operations
impl RedisCache
User profile cache operations
Sourcepub async fn set_user_profile<T: Serialize>(
&self,
user_id: Uuid,
profile: &T,
) -> Result<()>
pub async fn set_user_profile<T: Serialize>( &self, user_id: Uuid, profile: &T, ) -> Result<()>
Cache user profile
Sourcepub async fn get_user_profile<T: DeserializeOwned>(
&self,
user_id: Uuid,
) -> Result<Option<T>>
pub async fn get_user_profile<T: DeserializeOwned>( &self, user_id: Uuid, ) -> Result<Option<T>>
Get cached user profile
Sourcepub async fn invalidate_user_profile(&self, user_id: Uuid) -> Result<bool>
pub async fn invalidate_user_profile(&self, user_id: Uuid) -> Result<bool>
Invalidate user profile cache
Source§impl RedisCache
Token price cache operations
impl RedisCache
Token price cache operations
Source§impl RedisCache
Token metadata cache operations
impl RedisCache
Token metadata cache operations
Sourcepub async fn set_token_meta<T: Serialize>(
&self,
token_id: Uuid,
meta: &T,
) -> Result<()>
pub async fn set_token_meta<T: Serialize>( &self, token_id: Uuid, meta: &T, ) -> Result<()>
Cache token metadata
Sourcepub async fn get_token_meta<T: DeserializeOwned>(
&self,
token_id: Uuid,
) -> Result<Option<T>>
pub async fn get_token_meta<T: DeserializeOwned>( &self, token_id: Uuid, ) -> Result<Option<T>>
Get cached token metadata
Sourcepub async fn invalidate_token_meta(&self, token_id: Uuid) -> Result<bool>
pub async fn invalidate_token_meta(&self, token_id: Uuid) -> Result<bool>
Invalidate token metadata cache
Source§impl RedisCache
User balance cache operations
impl RedisCache
User balance cache operations
Sourcepub async fn set_balance(
&self,
user_id: Uuid,
token_id: Uuid,
balance: f64,
) -> Result<()>
pub async fn set_balance( &self, user_id: Uuid, token_id: Uuid, balance: f64, ) -> Result<()>
Cache user balance for a token
Sourcepub async fn get_balance(
&self,
user_id: Uuid,
token_id: Uuid,
) -> Result<Option<f64>>
pub async fn get_balance( &self, user_id: Uuid, token_id: Uuid, ) -> Result<Option<f64>>
Get cached balance
Sourcepub async fn invalidate_user_balances(&self, user_id: Uuid) -> Result<u64>
pub async fn invalidate_user_balances(&self, user_id: Uuid) -> Result<u64>
Invalidate all balances for a user
Sourcepub async fn invalidate_token_balances(&self, token_id: Uuid) -> Result<u64>
pub async fn invalidate_token_balances(&self, token_id: Uuid) -> Result<u64>
Invalidate all balances for a token
Source§impl RedisCache
Rate limiting operations
impl RedisCache
Rate limiting operations
Sourcepub async fn check_rate_limit(
&self,
identifier: &str,
limit: u64,
window_secs: u64,
) -> Result<(u64, bool)>
pub async fn check_rate_limit( &self, identifier: &str, limit: u64, window_secs: u64, ) -> Result<(u64, bool)>
Check and increment rate limit Returns (current_count, is_allowed)
Sourcepub async fn get_rate_limit_count(&self, identifier: &str) -> Result<u64>
pub async fn get_rate_limit_count(&self, identifier: &str) -> Result<u64>
Get current rate limit count
Sourcepub async fn reset_rate_limit(&self, identifier: &str) -> Result<bool>
pub async fn reset_rate_limit(&self, identifier: &str) -> Result<bool>
Reset rate limit for identifier
Trait Implementations§
Source§impl Clone for RedisCache
impl Clone for RedisCache
Source§fn clone(&self) -> RedisCache
fn clone(&self) -> RedisCache
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto 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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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