Skip to main content

RedisStorage

Struct RedisStorage 

Source
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

Source

pub fn new(url: &str) -> RedisResult<Self>

Connects to the Redis server at url.

Source

pub fn from_env() -> RedisResult<Self>

Connects using REDIS_URL (falling back to REDIS_URI, then localhost).

Source

pub fn client(&self) -> &Client

Returns the underlying Redis client.

Source

pub async fn get_value(&self, key: &str) -> RedisResult<Option<String>>

Gets the string value for key, or None when absent.

Source

pub async fn set_value(&self, key: &str, value: &str) -> RedisResult<()>

Sets the string value for key.

Source

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.

Source

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.

Source

pub async fn delete_key(&self, key: &str) -> RedisResult<i64>

Deletes key and returns the number of keys removed.

Lazily frees key with UNLINK and returns the number of keys removed.

Source

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.

Source

pub async fn key_exists(&self, key: &str) -> RedisResult<bool>

Returns true when key exists.

Source

pub async fn increment_value(&self, key: &str) -> RedisResult<i64>

Increments the integer at key by 1 and returns the new value.

Source

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.

Source

pub async fn decrement_value(&self, key: &str) -> RedisResult<i64>

Decrements the integer at key by 1 and returns the new value.

Source

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.

Source

pub async fn idle_time(&self, key: &str) -> RedisResult<i64>

Returns seconds since key was last accessed (OBJECT IDLETIME).

Source

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.

Source

pub async fn get_time_to_live(&self, key: &str) -> RedisResult<i64>

Returns the TTL of key in seconds.

Source

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.

Source

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.

Source

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.

Source

pub async fn set_hash_value( &self, key: &str, field: &str, value: &str, ) -> RedisResult<()>

Sets a hash field value.

Source

pub async fn delete_hash_field( &self, key: &str, field: &str, ) -> RedisResult<i64>

Deletes a hash field and returns the number of fields removed.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn get_all_hash_fields( &self, key: &str, ) -> RedisResult<HashMap<String, String>>

Returns all fields and values of a hash.

Source

pub async fn get_hash_keys(&self, key: &str) -> RedisResult<Vec<String>>

Returns all field names of a hash.

Source

pub async fn get_hash_values(&self, key: &str) -> RedisResult<Vec<String>>

Returns all values of a hash.

Source

pub async fn hash_field_exists( &self, key: &str, field: &str, ) -> RedisResult<bool>

Returns true when a hash field exists.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn get_list_length(&self, key: &str) -> RedisResult<i64>

Returns the length of the list at key.

Source

pub async fn get_list_range( &self, key: &str, start: i64, stop: i64, ) -> RedisResult<Vec<String>>

Returns list elements from start to stop inclusive.

Source

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.

Source

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.

Source

pub async fn get_set_members(&self, key: &str) -> RedisResult<Vec<String>>

Returns all members of the set.

Source

pub async fn is_set_member(&self, key: &str, member: &str) -> RedisResult<bool>

Returns true when member belongs to the set.

Source

pub async fn get_set_size(&self, key: &str) -> RedisResult<i64>

Returns the number of members in the set.

Source

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.

Source

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.

Source

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.

Source

pub async fn get_sorted_set_score( &self, key: &str, member: &str, ) -> RedisResult<Option<f64>>

Returns the score of member, or None when absent.

Source

pub async fn get_sorted_set_size(&self, key: &str) -> RedisResult<i64>

Returns the number of members in the sorted set.

Source

pub async fn remove_expiration(&self, key: &str) -> RedisResult<bool>

Removes the expiration from key; returns true when a timeout was removed.

Source

pub async fn rename_key(&self, old_key: &str, new_key: &str) -> RedisResult<()>

Renames old_key to new_key, overwriting any existing destination.

Source

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.

Source

pub async fn scan_keys_default(&self, pattern: &str) -> RedisResult<Vec<String>>

Scans keys matching pattern with a count hint of 250.

Source

pub async fn find_keys(&self, pattern: &str) -> RedisResult<Vec<String>>

👎Deprecated:

Use scan_keys instead to avoid blocking Redis

Deprecated alias for RedisStorage::scan_keys_default; prefer scan_keys to avoid blocking Redis.

Trait Implementations§

Source§

impl Clone for RedisStorage

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CompatExt for T

Source§

fn compat(self) -> Compat<T>
where T: Sized,

Applies the Compat adapter by value. Read more
Source§

fn compat_ref(&self) -> Compat<&T>

Applies the Compat adapter by shared reference. Read more
Source§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the Compat adapter by mutable reference. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more