Skip to main content

SecondaryStorage

Trait SecondaryStorage 

Source
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§

Source

fn get<'a>(&'a self, key: &'a str) -> SecondaryStorageFuture<'a, Option<String>>

Source

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.

Source

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).

Source

fn delete<'a>(&'a self, key: &'a str) -> SecondaryStorageFuture<'a, ()>

Source

fn take<'a>( &'a self, key: &'a str, ) -> SecondaryStorageFuture<'a, Option<String>>

Atomically remove and return the stored value when present.

Source

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.

Source

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".

Implementors§