1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use std::time::Duration;

use crate::{async_trait, Data, Error};

/// A Storage Trait
#[async_trait]
pub trait Storage: Send + Sync {
    /// Get a data from storage by the key
    async fn get(&self, key: &str) -> Result<Option<Data>, Error>;

    /// Set a session to storage
    async fn set(&self, key: &str, val: Data, exp: &Duration) -> Result<(), Error>;

    /// Remove a data from storage by the key
    async fn remove(&self, key: &str) -> Result<(), Error>;

    /// Reset the storage and remove all keys
    async fn reset(&self) -> Result<(), Error> {
        Ok(())
    }

    /// Close the connection
    async fn close(&self) -> Result<(), Error> {
        Ok(())
    }
}