pub trait SecondaryStorage:
Send
+ Sync
+ 'static {
// Required methods
fn get<'a>(
&'a self,
key: &'a str,
) -> SecondaryStorageFuture<'a, Option<String>>;
fn set<'a>(
&'a self,
key: &'a str,
value: String,
ttl_seconds: Option<u64>,
) -> SecondaryStorageFuture<'a, ()>;
fn set_if_not_exists<'a>(
&'a self,
key: &'a str,
value: String,
ttl_seconds: Option<u64>,
) -> SecondaryStorageFuture<'a, bool>;
fn delete<'a>(&'a self, key: &'a str) -> SecondaryStorageFuture<'a, ()>;
fn take<'a>(
&'a self,
key: &'a str,
) -> SecondaryStorageFuture<'a, Option<String>>;
fn compare_and_set<'a>(
&'a self,
key: &'a str,
expected: Option<String>,
value: String,
ttl_seconds: Option<u64>,
) -> SecondaryStorageFuture<'a, bool>;
fn delete_if_value<'a>(
&'a self,
key: &'a str,
expected: Option<String>,
) -> SecondaryStorageFuture<'a, bool>;
}Expand description
Async key-value storage for plugin data that can live outside the primary database.
Required Methods§
fn get<'a>(&'a self, key: &'a str) -> SecondaryStorageFuture<'a, Option<String>>
Sourcefn set<'a>(
&'a self,
key: &'a str,
value: String,
ttl_seconds: Option<u64>,
) -> SecondaryStorageFuture<'a, ()>
fn set<'a>( &'a self, key: &'a str, value: String, ttl_seconds: Option<u64>, ) -> SecondaryStorageFuture<'a, ()>
ttl_seconds == Some(0) means the value is already expired: implementations
must remove any existing key and must not store value without expiry.
Sourcefn set_if_not_exists<'a>(
&'a self,
key: &'a str,
value: String,
ttl_seconds: Option<u64>,
) -> SecondaryStorageFuture<'a, bool>
fn set_if_not_exists<'a>( &'a self, key: &'a str, value: String, ttl_seconds: Option<u64>, ) -> SecondaryStorageFuture<'a, bool>
Store value only when key is absent.
Returns Ok(true) when the key was created, or Ok(false) when it already existed.
ttl_seconds == Some(0) means the value is already expired: implementations must
not create or delete the key and must return Ok(false).
fn delete<'a>(&'a self, key: &'a str) -> SecondaryStorageFuture<'a, ()>
Sourcefn take<'a>(
&'a self,
key: &'a str,
) -> SecondaryStorageFuture<'a, Option<String>>
fn take<'a>( &'a self, key: &'a str, ) -> SecondaryStorageFuture<'a, Option<String>>
Atomically remove and return the stored value when present.
Sourcefn compare_and_set<'a>(
&'a self,
key: &'a str,
expected: Option<String>,
value: String,
ttl_seconds: Option<u64>,
) -> SecondaryStorageFuture<'a, bool>
fn compare_and_set<'a>( &'a self, key: &'a str, expected: Option<String>, value: String, ttl_seconds: Option<u64>, ) -> SecondaryStorageFuture<'a, bool>
Atomically replace the key only when the currently stored value matches
expected. expected == None means the key must be absent.
Implementations must perform the comparison and replacement as a single
backend operation. A get followed by set is not sufficient for
shared or multi-process storage because concurrent writers can lose
updates between the read and write.
Returns Ok(true) when the replacement was applied.
Sourcefn delete_if_value<'a>(
&'a self,
key: &'a str,
expected: Option<String>,
) -> SecondaryStorageFuture<'a, bool>
fn delete_if_value<'a>( &'a self, key: &'a str, expected: Option<String>, ) -> SecondaryStorageFuture<'a, bool>
Atomically delete the key only when the currently stored value matches
expected. expected == None means the key must already be absent and
therefore no deletion is performed.
Implementations must perform the comparison and deletion as a single
backend operation. A get followed by delete is not sufficient for
shared or multi-process storage because concurrent writers can race the
deletion.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".