pub struct Cache { /* private fields */ }Implementations§
source§impl Cache
impl Cache
sourcepub fn new() -> Result<Self, CacheError>
pub fn new() -> Result<Self, CacheError>
Creates a new Cache instance.
This function establishes a connection to a Redis server and returns a Result containing the Cache instance if successful, or a Boxed error if an error occurs.
§Errors
Returns a Boxed error if:
- The URL for the Redis server is invalid or unreachable.
- The connection to the Redis server cannot be established.
§Example
use celp_sdk::cache::Cache;
let cache = Cache::new();sourcepub fn add_field(
&mut self,
key: &str,
field: &str,
value: &[u8],
) -> Result<i32, CacheError>
pub fn add_field( &mut self, key: &str, field: &str, value: &[u8], ) -> Result<i32, CacheError>
Adds a field and its corresponding value to a Redis hash.
§Arguments
key- The key of the Redis hash.field- The field to set.value- The value to set for the field.
§Example
use celp_sdk::cache::Cache;
let cache = Cache::new();
if let Ok(mut c) = cache {
c.add_field("celp:app_info", "restful-svc", "serialized-version-str".as_bytes());
}sourcepub fn get_fields(
&mut self,
key: &str,
) -> Result<HashMap<String, String>, CacheError>
pub fn get_fields( &mut self, key: &str, ) -> Result<HashMap<String, String>, CacheError>
sourcepub fn get_field_names(&mut self, key: &str) -> Result<Vec<String>, CacheError>
pub fn get_field_names(&mut self, key: &str) -> Result<Vec<String>, CacheError>
sourcepub fn get_field_value(
&mut self,
key: &str,
field: &str,
) -> Result<Option<String>, CacheError>
pub fn get_field_value( &mut self, key: &str, field: &str, ) -> Result<Option<String>, CacheError>
Retrieves a specific field’s value from a Redis hash.
§Arguments
key- The key of the Redis hash.field- The field whose value you want to retrieve.
§Example
use celp_sdk::cache::Cache;
let cache = Cache::new();
if let Ok(mut c) = cache {
let value = c.get_field_value("celp:app_info", "field_name");
}sourcepub fn field_exists(
&mut self,
key: &str,
field: &str,
) -> Result<bool, CacheError>
pub fn field_exists( &mut self, key: &str, field: &str, ) -> Result<bool, CacheError>
sourcepub fn delete_field(
&mut self,
key: &str,
field: &str,
) -> Result<bool, CacheError>
pub fn delete_field( &mut self, key: &str, field: &str, ) -> Result<bool, CacheError>
Auto Trait Implementations§
impl Freeze for Cache
impl !RefUnwindSafe for Cache
impl Send for Cache
impl Sync for Cache
impl Unpin for Cache
impl !UnwindSafe for Cache
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