Skip to main content

SortedSetManager

Struct SortedSetManager 

Source
pub struct SortedSetManager { /* private fields */ }
Expand description

Sorted Set data structure interface (Redis-compatible)

Provides scored, ordered collections with ranking and range query capabilities.

Implementations§

Source§

impl SortedSetManager

Source

pub async fn add<K, M>(&self, key: K, member: M, score: f64) -> Result<bool>
where K: AsRef<str>, M: AsRef<str>,

Add member with score to sorted set (ZADD)

§Example
client.sorted_set().add("leaderboard", "player1", 100.0).await?;
Source

pub async fn add_multiple<K>( &self, key: K, members: Vec<ScoredMember>, ) -> Result<usize>
where K: AsRef<str>,

Add multiple members with scores to sorted set (ZADD with array)

§Example
let members = vec![
    ScoredMember { member: "player1".to_string(), score: 100.0 },
    ScoredMember { member: "player2".to_string(), score: 200.0 },
];
client.sorted_set().add_multiple("leaderboard", members).await?;
Source

pub async fn rem<K>(&self, key: K, members: Vec<String>) -> Result<usize>
where K: AsRef<str>,

Remove members from sorted set (ZREM)

Source

pub async fn score<K, M>(&self, key: K, member: M) -> Result<Option<f64>>
where K: AsRef<str>, M: AsRef<str>,

Get score of a member (ZSCORE)

Source

pub async fn card<K>(&self, key: K) -> Result<usize>
where K: AsRef<str>,

Get cardinality (number of members) (ZCARD)

Source

pub async fn incr_by<K, M>( &self, key: K, member: M, increment: f64, ) -> Result<f64>
where K: AsRef<str>, M: AsRef<str>,

Increment score of member (ZINCRBY)

Source

pub async fn range<K>( &self, key: K, start: i64, stop: i64, with_scores: bool, ) -> Result<Vec<ScoredMember>>
where K: AsRef<str>,

Get range by rank (0-based index) (ZRANGE)

§Example
// Get top 10 from leaderboard
let top10 = client.sorted_set().range("leaderboard", 0, 9, true).await?;
for member in top10 {
    tracing::info!("{}: {}", member.member, member.score);
}
Source

pub async fn rev_range<K>( &self, key: K, start: i64, stop: i64, with_scores: bool, ) -> Result<Vec<ScoredMember>>
where K: AsRef<str>,

Get reverse range by rank (highest to lowest) (ZREVRANGE)

Source

pub async fn rank<K, M>(&self, key: K, member: M) -> Result<Option<usize>>
where K: AsRef<str>, M: AsRef<str>,

Get rank of member (0-based, lowest score = rank 0) (ZRANK)

Source

pub async fn rev_rank<K, M>(&self, key: K, member: M) -> Result<Option<usize>>
where K: AsRef<str>, M: AsRef<str>,

Get reverse rank of member (0-based, highest score = rank 0) (ZREVRANK)

Source

pub async fn count<K>(&self, key: K, min: f64, max: f64) -> Result<usize>
where K: AsRef<str>,

Count members with scores in range (ZCOUNT)

Source

pub async fn range_by_score<K>( &self, key: K, min: f64, max: f64, with_scores: bool, ) -> Result<Vec<ScoredMember>>
where K: AsRef<str>,

Get range by score (ZRANGEBYSCORE)

Source

pub async fn pop_min<K>( &self, key: K, count: usize, ) -> Result<Vec<ScoredMember>>
where K: AsRef<str>,

Pop minimum scored members (ZPOPMIN)

Source

pub async fn pop_max<K>( &self, key: K, count: usize, ) -> Result<Vec<ScoredMember>>
where K: AsRef<str>,

Pop maximum scored members (ZPOPMAX)

Source

pub async fn rem_range_by_rank<K>( &self, key: K, start: i64, stop: i64, ) -> Result<usize>
where K: AsRef<str>,

Remove members by rank range (ZREMRANGEBYRANK)

Source

pub async fn rem_range_by_score<K>( &self, key: K, min: f64, max: f64, ) -> Result<usize>
where K: AsRef<str>,

Remove members by score range (ZREMRANGEBYSCORE)

Source

pub async fn inter_store<D>( &self, destination: D, keys: Vec<&str>, weights: Option<Vec<f64>>, aggregate: &str, ) -> Result<usize>
where D: AsRef<str>,

Compute intersection and store in destination (ZINTERSTORE)

§Example
// Intersect two leaderboards
let count = client.sorted_set().inter_store(
    "combined",
    vec!["board1", "board2"],
    None,
    "sum",
).await?;
Source

pub async fn union_store<D>( &self, destination: D, keys: Vec<&str>, weights: Option<Vec<f64>>, aggregate: &str, ) -> Result<usize>
where D: AsRef<str>,

Compute union and store in destination (ZUNIONSTORE)

Source

pub async fn diff_store<D>( &self, destination: D, keys: Vec<&str>, ) -> Result<usize>
where D: AsRef<str>,

Compute difference and store in destination (ZDIFFSTORE)

Source

pub async fn stats(&self) -> Result<SortedSetStats>

Get statistics

Trait Implementations§

Source§

impl Clone for SortedSetManager

Source§

fn clone(&self) -> SortedSetManager

Returns a duplicate of the value. Read more
1.0.0 · 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<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> 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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