pub trait Store: Send + Sync {
// Required methods
fn initialize(
&self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>;
fn get(
&self,
key: &str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, StoreError>> + Send + '_>>;
fn list(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<StoreModel>, StoreError>> + Send + '_>>;
fn set(
&self,
key: &str,
value: Value,
ttl: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<Option<StoreModel>, StoreError>> + Send + '_>>;
fn remove(
&self,
key: &str,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>;
fn remove_many(
&self,
keys: &[&str],
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>;
fn clear(
&self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>;
}Required Methods§
sourcefn initialize(
&self,
) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>
fn initialize( &self, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + '_>>
Initializes the storage backend. This method should perform any necessary setup for the storage backend, such as establishing database connections or ensuring the existence of required files or schemas.
§Returns
Ok(())on success.Err(StoreError)if initialisation fails.
sourcefn get(
&self,
key: &str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>, StoreError>> + Send + '_>>
fn get( &self, key: &str, ) -> Pin<Box<dyn Future<Output = Result<Option<Value>, StoreError>> + Send + '_>>
Retrieves a value associated with a given key from the store.
§Arguments
key: A string slice that holds the key for the value to be retrieved.
§Returns
Ok(Some(Value))if the key exists and the value is successfully retrieved.Ok(None)if the key does not exist.Err(StoreError)if there is an error retrieving the value.
sourcefn list(
&self,
) -> Pin<Box<dyn Future<Output = Result<Vec<StoreModel>, StoreError>> + Send + '_>>
fn list( &self, ) -> Pin<Box<dyn Future<Output = Result<Vec<StoreModel>, StoreError>> + Send + '_>>
Lists all key-value pairs stored in the store.
§Returns
Ok(Vec<StoreModel>)containing all the key-value pairs in the store.Err(StoreError)if there is an error listing the key-value pairs.
sourcefn set(
&self,
key: &str,
value: Value,
ttl: Option<u64>,
) -> Pin<Box<dyn Future<Output = Result<Option<StoreModel>, StoreError>> + Send + '_>>
fn set( &self, key: &str, value: Value, ttl: Option<u64>, ) -> Pin<Box<dyn Future<Output = Result<Option<StoreModel>, StoreError>> + Send + '_>>
Sets a value for a given key in the store, with an optional time-to-live (TTL).
§Arguments
key: The key under which the value is stored.value: The value to set, represented as aserde_json::Value.ttl: An optional u64 representing the time-to-live in seconds.
§Returns
Ok(())if the value is successfully set.Err(StoreError)if there is an error setting the value.