Struct Cache

Source
pub struct Cache { /* private fields */ }

Implementations§

Source§

impl Cache

Source

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();
Source

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());
}
Source

pub fn get_fields( &mut self, key: &str, ) -> Result<HashMap<String, String>, CacheError>

Retrieves all fields and their corresponding values for a key from a Redis hash.

§Arguments
  • key - The key of the Redis hash.
§Example
use celp_sdk::cache::Cache;

let cache = Cache::new();
if let Ok(mut c) = cache {
    let data = c.get_fields("celp:app_info");
}
Source

pub fn get_field_names(&mut self, key: &str) -> Result<Vec<String>, CacheError>

Retrieves all field names from a Redis hash for a given key.

§Arguments
  • key - The key of the Redis hash.
§Example
use celp_sdk::cache::Cache;

let cache = Cache::new();
if let Ok(mut c) = cache {
    let field_names = c.get_field_names("celp:app_info");
}
Source

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");
}
Source

pub fn field_exists( &mut self, key: &str, field: &str, ) -> Result<bool, CacheError>

Checks if a specific field exists in a Redis hash.

§Arguments
  • key - The key of the Redis hash.
  • field - The field you want to check for existence.
§Example
use celp_sdk::cache::Cache;

let cache = Cache::new();
if let Ok(mut c) = cache {
    let exists = c.field_exists("celp:app_info", "field_name");
}
Source

pub fn delete_field( &mut self, key: &str, field: &str, ) -> Result<bool, CacheError>

Deletes a specific field from a Redis hash.

§Arguments
  • key - The key of the Redis hash.
  • field - The field you want to delete.
§Example
use celp_sdk::cache::Cache;

let cache = Cache::new();
if let Ok(mut c) = cache {
    let deleted = c.delete_field("celp:app_info", "field_name");
}

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> 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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T