RedisCache

Struct RedisCache 

Source
pub struct RedisCache { /* private fields */ }
Expand description

Redis cache client with connection management

Implementations§

Source§

impl RedisCache

Source

pub async fn new(config: CacheConfig) -> Result<Self>

Create a new Redis cache connection

Source

pub async fn get<T: DeserializeOwned>(&self, key: &str) -> Result<Option<T>>

Get a value from cache

Source

pub async fn set<T: Serialize>( &self, key: &str, value: &T, ttl_secs: u64, ) -> Result<()>

Set a value in cache with TTL

Source

pub async fn set_default<T: Serialize>( &self, key: &str, value: &T, ) -> Result<()>

Set a value with default TTL

Source

pub async fn delete(&self, key: &str) -> Result<bool>

Delete a key from cache

Source

pub async fn delete_pattern(&self, pattern: &str) -> Result<u64>

Delete multiple keys matching a pattern

Source

pub async fn exists(&self, key: &str) -> Result<bool>

Check if a key exists

Source

pub async fn incr(&self, key: &str) -> Result<i64>

Increment a counter (for rate limiting)

Source

pub async fn incr_with_expiry(&self, key: &str, ttl_secs: u64) -> Result<i64>

Increment with expiry (for rate limiting windows)

Source

pub async fn expire(&self, key: &str, ttl_secs: u64) -> Result<bool>

Set TTL on existing key

Source

pub async fn ttl(&self, key: &str) -> Result<i64>

Get remaining TTL for a key

Source

pub async fn try_lock( &self, resource: &str, ttl_secs: u64, ) -> Result<Option<String>>

Try to acquire a distributed lock

Source

pub async fn release_lock(&self, resource: &str, lock_id: &str) -> Result<bool>

Release a distributed lock

Source

pub async fn health_check(&self) -> Result<bool>

Health check

Source§

impl RedisCache

User session cache operations

Source

pub async fn set_session(&self, session_id: &str, user_id: Uuid) -> Result<()>

Cache a user session

Source

pub async fn get_session(&self, session_id: &str) -> Result<Option<Uuid>>

Get user ID from session

Source

pub async fn invalidate_session(&self, session_id: &str) -> Result<bool>

Invalidate a session

Source

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

Source

pub async fn set_user_profile<T: Serialize>( &self, user_id: Uuid, profile: &T, ) -> Result<()>

Cache user profile

Source

pub async fn get_user_profile<T: DeserializeOwned>( &self, user_id: Uuid, ) -> Result<Option<T>>

Get cached user profile

Source

pub async fn invalidate_user_profile(&self, user_id: Uuid) -> Result<bool>

Invalidate user profile cache

Source§

impl RedisCache

Token price cache operations

Source

pub async fn set_token_price( &self, token_id: Uuid, price_btc: f64, ) -> Result<()>

Cache token price

Source

pub async fn get_token_price(&self, token_id: Uuid) -> Result<Option<f64>>

Get cached token price

Source

pub async fn set_token_prices(&self, prices: &[(Uuid, f64)]) -> Result<()>

Cache multiple token prices

Source§

impl RedisCache

Token metadata cache operations

Source

pub async fn set_token_meta<T: Serialize>( &self, token_id: Uuid, meta: &T, ) -> Result<()>

Cache token metadata

Source

pub async fn get_token_meta<T: DeserializeOwned>( &self, token_id: Uuid, ) -> Result<Option<T>>

Get cached token metadata

Source

pub async fn invalidate_token_meta(&self, token_id: Uuid) -> Result<bool>

Invalidate token metadata cache

Source§

impl RedisCache

User balance cache operations

Source

pub async fn set_balance( &self, user_id: Uuid, token_id: Uuid, balance: f64, ) -> Result<()>

Cache user balance for a token

Source

pub async fn get_balance( &self, user_id: Uuid, token_id: Uuid, ) -> Result<Option<f64>>

Get cached balance

Source

pub async fn invalidate_user_balances(&self, user_id: Uuid) -> Result<u64>

Invalidate all balances for a user

Source

pub async fn invalidate_token_balances(&self, token_id: Uuid) -> Result<u64>

Invalidate all balances for a token

Source§

impl RedisCache

Rate limiting operations

Source

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)

Source

pub async fn get_rate_limit_count(&self, identifier: &str) -> Result<u64>

Get current rate limit count

Source

pub async fn reset_rate_limit(&self, identifier: &str) -> Result<bool>

Reset rate limit for identifier

Trait Implementations§

Source§

impl Clone for RedisCache

Source§

fn clone(&self) -> RedisCache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more