pub struct CacheClient { /* private fields */ }Implementations§
Source§impl CacheClient
impl CacheClient
Sourcepub async fn new(
url: &str,
db_index: Option<u8>,
cache_capacity: usize,
connection_size: u32,
) -> Result<Self>
pub async fn new( url: &str, db_index: Option<u8>, cache_capacity: usize, connection_size: u32, ) -> Result<Self>
Initializes a new CacheClient with a connection pool and an optional in-memory cache.
Sourcepub async fn set_json<T: Serialize>(&self, key: &str, value: &T) -> Result<()>
pub async fn set_json<T: Serialize>(&self, key: &str, value: &T) -> Result<()>
将 JSON 数据写入缓存,并同时写入 Redis
Sourcepub async fn get_json<T: DeserializeOwned>(
&self,
key: &str,
) -> Result<Option<T>>
pub async fn get_json<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>>
从缓存或 Redis 中获取 JSON 数据 从缓存或 Redis 中获取 JSON 数据
Sourcepub async fn set_json_ex<T: Serialize>(
&self,
key: &str,
value: &T,
sec: u64,
) -> Result<()>
pub async fn set_json_ex<T: Serialize>( &self, key: &str, value: &T, sec: u64, ) -> Result<()>
将 JSON 数据写入缓存并设置过期时间
Sourcepub async fn keys(&self, pattern: &str) -> Result<Vec<String>>
pub async fn keys(&self, pattern: &str) -> Result<Vec<String>>
Get all keys matching a pattern.
Sourcepub async fn add_cache_json<T: Serialize>(
&self,
key: &str,
value: &T,
) -> Result<()>
pub async fn add_cache_json<T: Serialize>( &self, key: &str, value: &T, ) -> Result<()>
Add JSON data to cache with a 60-second expiration time.
Sourcepub async fn get_cache_json<T: DeserializeOwned>(
&self,
key: &str,
) -> Result<Option<T>>
pub async fn get_cache_json<T: DeserializeOwned>( &self, key: &str, ) -> Result<Option<T>>
Get JSON data from cache.
Trait Implementations§
Source§impl Clone for CacheClient
impl Clone for CacheClient
Source§fn clone(&self) -> CacheClient
fn clone(&self) -> CacheClient
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CacheClient
impl !RefUnwindSafe for CacheClient
impl Send for CacheClient
impl Sync for CacheClient
impl Unpin for CacheClient
impl !UnwindSafe for CacheClient
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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