pub struct RedisBackend { /* private fields */ }Expand description
An implementation of ExpiryStore based on redis
using redis-rs async runtime
§Example
use basteh::Basteh;
use basteh_redis::{RedisBackend, ConnectionInfo, RedisConnectionInfo, ConnectionAddr};
let provider = RedisBackend::connect_default();
// OR
let connection_info = ConnectionInfo {
addr: ConnectionAddr::Tcp("127.0.0.1".to_string(), 1234).into(),
redis: RedisConnectionInfo{
db: 0,
username: Some("god".to_string()),
password: Some("bless".to_string()),
}
};
let provider = RedisBackend::connect(connection_info).await.expect("Redis connection failed");
let basteh = Basteh::build().provider(provider).finish();Implementations§
Source§impl RedisBackend
impl RedisBackend
Sourcepub async fn connect(connection_info: ConnectionInfo) -> RedisResult<Self>
pub async fn connect(connection_info: ConnectionInfo) -> RedisResult<Self>
Connect using the provided connection info
Sourcepub async fn connect_default() -> RedisResult<Self>
pub async fn connect_default() -> RedisResult<Self>
Connect using the default redis port on local machine
Trait Implementations§
Source§impl Clone for RedisBackend
impl Clone for RedisBackend
Source§fn clone(&self) -> RedisBackend
fn clone(&self) -> RedisBackend
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Provider for RedisBackend
impl Provider for RedisBackend
Source§fn keys<'life0, 'life1, 'async_trait>(
&'life0 self,
scope: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Iterator<Item = Vec<u8>>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn keys<'life0, 'life1, 'async_trait>(
&'life0 self,
scope: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Box<dyn Iterator<Item = Vec<u8>>>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Set a key-value pair, if the key already exist, value should be overwritten
Source§fn set<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
value: Value<'life3>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn set<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
value: Value<'life3>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Set a key-value pair, if the key already exist, value should be overwritten
Source§fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Get a single value for specified key, it should return None if the value does not exist
Source§fn get_range<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
start: i64,
end: i64,
) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn get_range<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
start: i64,
end: i64,
) -> Pin<Box<dyn Future<Output = Result<Vec<OwnedValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Get a list of values for specified key, it should return an empty vector if the value does not exist
Source§fn push<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
value: Value<'life3>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn push<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
value: Value<'life3>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Push a value into the list associated with this key, if the key has a value of
another type, it should return error
Source§fn push_multiple<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
value: Vec<Value<'life3>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn push_multiple<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
value: Vec<Value<'life3>>,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Push multiple values into the list associated with this key, if the key has a value of
another type, it should return error
Source§fn pop<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn pop<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Pop a value from the list associated with this key, if the key has a value of
another type, it should return error
Source§fn mutate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
mutations: Mutation,
) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn mutate<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
mutations: Mutation,
) -> Pin<Box<dyn Future<Output = Result<i64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Mutate and get a value for specified key, it should set the value to 0 if it doesn’t exist
Source§fn remove<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn remove<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<OwnedValue>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Delete the key from storage, if the key doesn’t exist, it shouldn’t return an error
Source§fn contains_key<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn contains_key<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Check if key exist in storage
Source§fn persist<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn persist<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Remove all expiry requests from a key and make it persistent,
the persistenty can be overwriten by calling expire on the key.
Source§fn expiry<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<Duration>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn expiry<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<Duration>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Gets expiry for a key, returning None means it doesn’t have an expiry,
if the provider can’t return an expiry, it should return an error instead.
The result of this function can have some error, but it should be documented.
Source§fn expire<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
expire_in: Duration,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn expire<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
expire_in: Duration,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Sets an expiry for a key, the key may or may not be removed based on
implementation, but it should be guaranteed that it won’t appear in
get based methods or contains checks after the period specified.
Source§fn set_expiring<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
value: Value<'life3>,
expire_in: Duration,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn set_expiring<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
value: Value<'life3>,
expire_in: Duration,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Set a key-value for a duration of time, if the key already exists, it should overwrite
both the value and the expiry for that key.
Source§fn extend<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
expire_in: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), BastehError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn extend<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
expire_in: Duration,
) -> Pin<Box<dyn Future<Output = Result<(), BastehError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Extend expiry for a key for another duration of time.
If the key doesn’t have an expiry, it should be equivalent of calling expire.
Source§fn get_expiring<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<(OwnedValue, Option<Duration>)>, BastehError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn get_expiring<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
scope: &'life1 str,
key: &'life2 [u8],
) -> Pin<Box<dyn Future<Output = Result<Option<(OwnedValue, Option<Duration>)>, BastehError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Get the value and expiry for a key, it is possible to return None if the key doesn’t exist,
or return None for the expiry if the key is persistent.
Auto Trait Implementations§
impl Freeze for RedisBackend
impl !RefUnwindSafe for RedisBackend
impl Send for RedisBackend
impl Sync for RedisBackend
impl Unpin for RedisBackend
impl !UnwindSafe for RedisBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more