pub struct RedisStorage { /* private fields */ }Expand description
Async Redis helper for strings, hashes, lists, sets, and sorted sets.
All operations open a multiplexed connection and return Redis errors to the caller.
Implementations§
Source§impl RedisStorage
impl RedisStorage
Sourcepub fn new(url: &str) -> RedisResult<Self>
pub fn new(url: &str) -> RedisResult<Self>
Connects to the Redis server at url.
Sourcepub fn from_env() -> RedisResult<Self>
pub fn from_env() -> RedisResult<Self>
Connects using REDIS_URL (falling back to REDIS_URI, then localhost).
Sourcepub async fn get_value(&self, key: &str) -> RedisResult<Option<String>>
pub async fn get_value(&self, key: &str) -> RedisResult<Option<String>>
Gets the string value for key, or None when absent.
Sourcepub async fn set_value(&self, key: &str, value: &str) -> RedisResult<()>
pub async fn set_value(&self, key: &str, value: &str) -> RedisResult<()>
Sets the string value for key.
Sourcepub async fn set_value_with_expiration(
&self,
key: &str,
value: &str,
seconds: u64,
) -> RedisResult<()>
pub async fn set_value_with_expiration( &self, key: &str, value: &str, seconds: u64, ) -> RedisResult<()>
Sets the string value for key with a TTL of seconds.
Sourcepub async fn set_value_if_absent(
&self,
key: &str,
value: &str,
) -> RedisResult<bool>
pub async fn set_value_if_absent( &self, key: &str, value: &str, ) -> RedisResult<bool>
Sets key only when absent; returns true when the key was set.
Sourcepub async fn delete_key(&self, key: &str) -> RedisResult<i64>
pub async fn delete_key(&self, key: &str) -> RedisResult<i64>
Deletes key and returns the number of keys removed.
Sourcepub async fn unlink_key(&self, key: &str) -> RedisResult<i64>
pub async fn unlink_key(&self, key: &str) -> RedisResult<i64>
Lazily frees key with UNLINK and returns the number of keys removed.
Sourcepub async fn delete_keys(&self, keys: &[String]) -> RedisResult<i64>
pub async fn delete_keys(&self, keys: &[String]) -> RedisResult<i64>
Deletes all given keys and returns the number removed; returns 0 for an empty list.
Sourcepub async fn key_exists(&self, key: &str) -> RedisResult<bool>
pub async fn key_exists(&self, key: &str) -> RedisResult<bool>
Returns true when key exists.
Sourcepub async fn increment_value(&self, key: &str) -> RedisResult<i64>
pub async fn increment_value(&self, key: &str) -> RedisResult<i64>
Increments the integer at key by 1 and returns the new value.
Sourcepub async fn increment_value_by(
&self,
key: &str,
delta: i64,
) -> RedisResult<i64>
pub async fn increment_value_by( &self, key: &str, delta: i64, ) -> RedisResult<i64>
Increments the integer at key by delta and returns the new value.
Sourcepub async fn decrement_value(&self, key: &str) -> RedisResult<i64>
pub async fn decrement_value(&self, key: &str) -> RedisResult<i64>
Decrements the integer at key by 1 and returns the new value.
Sourcepub async fn decrement_value_by(
&self,
key: &str,
delta: i64,
) -> RedisResult<i64>
pub async fn decrement_value_by( &self, key: &str, delta: i64, ) -> RedisResult<i64>
Decrements the integer at key by delta and returns the new value.
Sourcepub async fn idle_time(&self, key: &str) -> RedisResult<i64>
pub async fn idle_time(&self, key: &str) -> RedisResult<i64>
Returns seconds since key was last accessed (OBJECT IDLETIME).
Sourcepub async fn set_expiration(&self, key: &str, seconds: u64) -> RedisResult<bool>
pub async fn set_expiration(&self, key: &str, seconds: u64) -> RedisResult<bool>
Sets the TTL of key to seconds; returns true when the timeout was set.
Sourcepub async fn get_time_to_live(&self, key: &str) -> RedisResult<i64>
pub async fn get_time_to_live(&self, key: &str) -> RedisResult<i64>
Returns the TTL of key in seconds.
Sourcepub async fn get_multiple_values(
&self,
keys: &[String],
) -> RedisResult<Vec<Option<String>>>
pub async fn get_multiple_values( &self, keys: &[String], ) -> RedisResult<Vec<Option<String>>>
Gets the values for several keys at once; missing keys yield None. Empty input returns empty output.
Sourcepub async fn set_multiple_values(
&self,
kv: &HashMap<String, String>,
) -> RedisResult<()>
pub async fn set_multiple_values( &self, kv: &HashMap<String, String>, ) -> RedisResult<()>
Sets several key-value pairs at once with MSET; does nothing for empty input.
Sourcepub async fn get_hash_value(
&self,
key: &str,
field: &str,
) -> RedisResult<Option<String>>
pub async fn get_hash_value( &self, key: &str, field: &str, ) -> RedisResult<Option<String>>
Gets a hash field value, or None when the key or field is absent.
Sourcepub async fn set_hash_value(
&self,
key: &str,
field: &str,
value: &str,
) -> RedisResult<()>
pub async fn set_hash_value( &self, key: &str, field: &str, value: &str, ) -> RedisResult<()>
Sets a hash field value.
Sourcepub async fn delete_hash_field(
&self,
key: &str,
field: &str,
) -> RedisResult<i64>
pub async fn delete_hash_field( &self, key: &str, field: &str, ) -> RedisResult<i64>
Deletes a hash field and returns the number of fields removed.
Sourcepub async fn set_hash_values(
&self,
key: &str,
field_values: &HashMap<String, String>,
) -> RedisResult<()>
pub async fn set_hash_values( &self, key: &str, field_values: &HashMap<String, String>, ) -> RedisResult<()>
Sets several hash fields at once; does nothing for empty input.
Sourcepub async fn set_hash_value_if_absent(
&self,
key: &str,
field: &str,
value: &str,
) -> RedisResult<bool>
pub async fn set_hash_value_if_absent( &self, key: &str, field: &str, value: &str, ) -> RedisResult<bool>
Sets a hash field only when absent; returns true when the field was set.
Sourcepub async fn increment_hash_field(
&self,
key: &str,
field: &str,
delta: i64,
) -> RedisResult<i64>
pub async fn increment_hash_field( &self, key: &str, field: &str, delta: i64, ) -> RedisResult<i64>
Increments a hash integer field by delta and returns the new value.
Sourcepub async fn decrement_hash_field(
&self,
key: &str,
field: &str,
delta: i64,
) -> RedisResult<i64>
pub async fn decrement_hash_field( &self, key: &str, field: &str, delta: i64, ) -> RedisResult<i64>
Decrements a hash integer field by delta and returns the new value.
Sourcepub async fn get_all_hash_fields(
&self,
key: &str,
) -> RedisResult<HashMap<String, String>>
pub async fn get_all_hash_fields( &self, key: &str, ) -> RedisResult<HashMap<String, String>>
Returns all fields and values of a hash.
Sourcepub async fn get_hash_keys(&self, key: &str) -> RedisResult<Vec<String>>
pub async fn get_hash_keys(&self, key: &str) -> RedisResult<Vec<String>>
Returns all field names of a hash.
Sourcepub async fn get_hash_values(&self, key: &str) -> RedisResult<Vec<String>>
pub async fn get_hash_values(&self, key: &str) -> RedisResult<Vec<String>>
Returns all values of a hash.
Sourcepub async fn hash_field_exists(
&self,
key: &str,
field: &str,
) -> RedisResult<bool>
pub async fn hash_field_exists( &self, key: &str, field: &str, ) -> RedisResult<bool>
Returns true when a hash field exists.
Sourcepub async fn push_to_list_start(
&self,
key: &str,
value: &str,
) -> RedisResult<i64>
pub async fn push_to_list_start( &self, key: &str, value: &str, ) -> RedisResult<i64>
Prepends value to the list at key and returns the new length.
Sourcepub async fn push_to_list_end(&self, key: &str, value: &str) -> RedisResult<i64>
pub async fn push_to_list_end(&self, key: &str, value: &str) -> RedisResult<i64>
Appends value to the list at key and returns the new length.
Sourcepub async fn pop_from_list_start(
&self,
key: &str,
) -> RedisResult<Option<String>>
pub async fn pop_from_list_start( &self, key: &str, ) -> RedisResult<Option<String>>
Removes and returns the first element of the list, or None when empty.
Sourcepub async fn pop_from_list_end(&self, key: &str) -> RedisResult<Option<String>>
pub async fn pop_from_list_end(&self, key: &str) -> RedisResult<Option<String>>
Removes and returns the last element of the list, or None when empty.
Sourcepub async fn get_list_length(&self, key: &str) -> RedisResult<i64>
pub async fn get_list_length(&self, key: &str) -> RedisResult<i64>
Returns the length of the list at key.
Sourcepub async fn get_list_range(
&self,
key: &str,
start: i64,
stop: i64,
) -> RedisResult<Vec<String>>
pub async fn get_list_range( &self, key: &str, start: i64, stop: i64, ) -> RedisResult<Vec<String>>
Returns list elements from start to stop inclusive.
Sourcepub async fn add_to_set(&self, key: &str, member: &str) -> RedisResult<i64>
pub async fn add_to_set(&self, key: &str, member: &str) -> RedisResult<i64>
Adds member to the set and returns the number of members added.
Sourcepub async fn remove_from_set(&self, key: &str, member: &str) -> RedisResult<i64>
pub async fn remove_from_set(&self, key: &str, member: &str) -> RedisResult<i64>
Removes member from the set and returns the number of members removed.
Sourcepub async fn get_set_members(&self, key: &str) -> RedisResult<Vec<String>>
pub async fn get_set_members(&self, key: &str) -> RedisResult<Vec<String>>
Returns all members of the set.
Sourcepub async fn is_set_member(&self, key: &str, member: &str) -> RedisResult<bool>
pub async fn is_set_member(&self, key: &str, member: &str) -> RedisResult<bool>
Returns true when member belongs to the set.
Sourcepub async fn get_set_size(&self, key: &str) -> RedisResult<i64>
pub async fn get_set_size(&self, key: &str) -> RedisResult<i64>
Returns the number of members in the set.
Sourcepub async fn add_to_sorted_set(
&self,
key: &str,
score: f64,
member: &str,
) -> RedisResult<i64>
pub async fn add_to_sorted_set( &self, key: &str, score: f64, member: &str, ) -> RedisResult<i64>
Adds member with score to the sorted set and returns the number of members added.
Sourcepub async fn get_sorted_set_range(
&self,
key: &str,
start: i64,
stop: i64,
) -> RedisResult<Vec<String>>
pub async fn get_sorted_set_range( &self, key: &str, start: i64, stop: i64, ) -> RedisResult<Vec<String>>
Returns sorted-set members from start to stop inclusive, by ascending score.
Sourcepub async fn remove_from_sorted_set(
&self,
key: &str,
member: &str,
) -> RedisResult<i64>
pub async fn remove_from_sorted_set( &self, key: &str, member: &str, ) -> RedisResult<i64>
Removes member from the sorted set and returns the number of members removed.
Sourcepub async fn get_sorted_set_score(
&self,
key: &str,
member: &str,
) -> RedisResult<Option<f64>>
pub async fn get_sorted_set_score( &self, key: &str, member: &str, ) -> RedisResult<Option<f64>>
Returns the score of member, or None when absent.
Sourcepub async fn get_sorted_set_size(&self, key: &str) -> RedisResult<i64>
pub async fn get_sorted_set_size(&self, key: &str) -> RedisResult<i64>
Returns the number of members in the sorted set.
Sourcepub async fn remove_expiration(&self, key: &str) -> RedisResult<bool>
pub async fn remove_expiration(&self, key: &str) -> RedisResult<bool>
Removes the expiration from key; returns true when a timeout was removed.
Sourcepub async fn rename_key(&self, old_key: &str, new_key: &str) -> RedisResult<()>
pub async fn rename_key(&self, old_key: &str, new_key: &str) -> RedisResult<()>
Renames old_key to new_key, overwriting any existing destination.
Sourcepub async fn scan_keys(
&self,
pattern: &str,
count: usize,
) -> RedisResult<Vec<String>>
pub async fn scan_keys( &self, pattern: &str, count: usize, ) -> RedisResult<Vec<String>>
Collects keys matching pattern with a non-blocking incremental scan.
count is the COUNT hint for each scan round.
Sourcepub async fn scan_keys_default(&self, pattern: &str) -> RedisResult<Vec<String>>
pub async fn scan_keys_default(&self, pattern: &str) -> RedisResult<Vec<String>>
Scans keys matching pattern with a count hint of 250.
Sourcepub async fn find_keys(&self, pattern: &str) -> RedisResult<Vec<String>>
👎Deprecated: Use scan_keys instead to avoid blocking Redis
pub async fn find_keys(&self, pattern: &str) -> RedisResult<Vec<String>>
Use scan_keys instead to avoid blocking Redis
Deprecated alias for RedisStorage::scan_keys_default; prefer scan_keys to avoid blocking Redis.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RedisStorage
impl RefUnwindSafe for RedisStorage
impl Send for RedisStorage
impl Sync for RedisStorage
impl Unpin for RedisStorage
impl UnsafeUnpin for RedisStorage
impl UnwindSafe for RedisStorage
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more