use crate::{
commands,
error::Error,
interfaces::{ClientLike, FredResult},
types::{
sorted_sets::{AggregateOptions, MultipleWeights, MultipleZaddValues, Ordering, ZCmp, ZRange, ZSort},
FromValue,
Key,
Limit,
MultipleKeys,
MultipleValues,
SetOptions,
Value,
},
};
use fred_macros::rm_send_if;
use futures::Future;
use std::convert::TryInto;
#[rm_send_if(feature = "glommio")]
pub trait SortedSetsInterface: ClientLike + Sized {
fn bzmpop<R, K>(
&self,
timeout: f64,
keys: K,
sort: ZCmp,
count: Option<i64>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::sorted_sets::bzmpop(self, timeout, keys, sort, count)
.await?
.convert()
}
}
fn bzpopmin<R, K>(&self, keys: K, timeout: f64) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::sorted_sets::bzpopmin(self, keys, timeout).await?.convert()
}
}
fn bzpopmax<R, K>(&self, keys: K, timeout: f64) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::sorted_sets::bzpopmax(self, keys, timeout).await?.convert()
}
}
fn zadd<R, K, V>(
&self,
key: K,
options: Option<SetOptions>,
ordering: Option<Ordering>,
changed: bool,
incr: bool,
values: V,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<MultipleZaddValues> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(values);
commands::sorted_sets::zadd(self, key, options, ordering, changed, incr, values)
.await?
.convert()
}
}
fn zcard<R, K>(&self, key: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sorted_sets::zcard(self, key).await?.convert()
}
}
fn zcount<R, K>(&self, key: K, min: f64, max: f64) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sorted_sets::zcount(self, key, min, max).await?.convert()
}
}
fn zdiff<R, K>(&self, keys: K, withscores: bool) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::sorted_sets::zdiff(self, keys, withscores).await?.convert()
}
}
fn zdiffstore<R, D, K>(&self, dest: D, keys: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
D: Into<Key> + Send,
K: Into<MultipleKeys> + Send,
{
async move {
into!(dest, keys);
commands::sorted_sets::zdiffstore(self, dest, keys).await?.convert()
}
}
fn zincrby<R, K, V>(&self, key: K, increment: f64, member: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<Value> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(member);
commands::sorted_sets::zincrby(self, key, increment, member)
.await?
.convert()
}
}
fn zinter<R, K, W>(
&self,
keys: K,
weights: W,
aggregate: Option<AggregateOptions>,
withscores: bool,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
W: Into<MultipleWeights> + Send,
{
async move {
into!(keys, weights);
commands::sorted_sets::zinter(self, keys, weights, aggregate, withscores)
.await?
.convert()
}
}
fn zinterstore<R, D, K, W>(
&self,
dest: D,
keys: K,
weights: W,
aggregate: Option<AggregateOptions>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
D: Into<Key> + Send,
K: Into<MultipleKeys> + Send,
W: Into<MultipleWeights> + Send,
{
async move {
into!(dest, keys, weights);
commands::sorted_sets::zinterstore(self, dest, keys, weights, aggregate)
.await?
.convert()
}
}
fn zlexcount<R, K, M, N>(&self, key: K, min: M, max: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(min, max);
commands::sorted_sets::zlexcount(self, key, min, max).await?.convert()
}
}
fn zpopmax<R, K>(&self, key: K, count: Option<usize>) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sorted_sets::zpopmax(self, key, count).await?.convert()
}
}
fn zpopmin<R, K>(&self, key: K, count: Option<usize>) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sorted_sets::zpopmin(self, key, count).await?.convert()
}
}
fn zmpop<R, K>(&self, keys: K, sort: ZCmp, count: Option<i64>) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::sorted_sets::zmpop(self, keys, sort, count).await?.convert()
}
}
fn zrandmember<R, K>(&self, key: K, count: Option<(i64, bool)>) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sorted_sets::zrandmember(self, key, count).await?.convert()
}
}
fn zrangestore<R, D, S, M, N>(
&self,
dest: D,
source: S,
min: M,
max: N,
sort: Option<ZSort>,
rev: bool,
limit: Option<Limit>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
D: Into<Key> + Send,
S: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(dest, source);
try_into!(min, max);
commands::sorted_sets::zrangestore(self, dest, source, min, max, sort, rev, limit)
.await?
.convert()
}
}
fn zrange<R, K, M, N>(
&self,
key: K,
min: M,
max: N,
sort: Option<ZSort>,
rev: bool,
limit: Option<Limit>,
withscores: bool,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(min, max);
commands::sorted_sets::zrange(self, key, min, max, sort, rev, limit, withscores)
.await?
.convert()
}
}
fn zrangebylex<R, K, M, N>(
&self,
key: K,
min: M,
max: N,
limit: Option<Limit>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(min, max);
commands::sorted_sets::zrangebylex(self, key, min, max, limit)
.await?
.convert()
}
}
fn zrevrangebylex<R, K, M, N>(
&self,
key: K,
max: M,
min: N,
limit: Option<Limit>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(max, min);
commands::sorted_sets::zrevrangebylex(self, key, max, min, limit)
.await?
.convert()
}
}
fn zrangebyscore<R, K, M, N>(
&self,
key: K,
min: M,
max: N,
withscores: bool,
limit: Option<Limit>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(min, max);
commands::sorted_sets::zrangebyscore(self, key, min, max, withscores, limit)
.await?
.convert()
}
}
fn zrevrangebyscore<R, K, M, N>(
&self,
key: K,
max: M,
min: N,
withscores: bool,
limit: Option<Limit>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(max, min);
commands::sorted_sets::zrevrangebyscore(self, key, max, min, withscores, limit)
.await?
.convert()
}
}
fn zrank<R, K, V>(&self, key: K, member: V, withscore: bool) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<Value> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(member);
commands::sorted_sets::zrank(self, key, member, withscore)
.await?
.convert()
}
}
fn zrem<R, K, V>(&self, key: K, members: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<MultipleValues> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(members);
commands::sorted_sets::zrem(self, key, members).await?.convert()
}
}
fn zremrangebylex<R, K, M, N>(&self, key: K, min: M, max: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(min, max);
commands::sorted_sets::zremrangebylex(self, key, min, max)
.await?
.convert()
}
}
fn zremrangebyrank<R, K>(&self, key: K, start: i64, stop: i64) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sorted_sets::zremrangebyrank(self, key, start, stop)
.await?
.convert()
}
}
fn zremrangebyscore<R, K, M, N>(&self, key: K, min: M, max: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
M: TryInto<ZRange> + Send,
M::Error: Into<Error> + Send,
N: TryInto<ZRange> + Send,
N::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(min, max);
commands::sorted_sets::zremrangebyscore(self, key, min, max)
.await?
.convert()
}
}
fn zrevrange<R, K>(
&self,
key: K,
start: i64,
stop: i64,
withscores: bool,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sorted_sets::zrevrange(self, key, start, stop, withscores)
.await?
.convert()
}
}
fn zrevrank<R, K, V>(&self, key: K, member: V, withscore: bool) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<Value> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(member);
commands::sorted_sets::zrevrank(self, key, member, withscore)
.await?
.convert()
}
}
fn zscore<R, K, V>(&self, key: K, member: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<Value> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(member);
commands::sorted_sets::zscore(self, key, member).await?.convert()
}
}
fn zunion<R, K, W>(
&self,
keys: K,
weights: W,
aggregate: Option<AggregateOptions>,
withscores: bool,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
W: Into<MultipleWeights> + Send,
{
async move {
into!(keys, weights);
commands::sorted_sets::zunion(self, keys, weights, aggregate, withscores)
.await?
.convert()
}
}
fn zunionstore<R, D, K, W>(
&self,
dest: D,
keys: K,
weights: W,
aggregate: Option<AggregateOptions>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
D: Into<Key> + Send,
K: Into<MultipleKeys> + Send,
W: Into<MultipleWeights> + Send,
{
async move {
into!(dest, keys, weights);
commands::sorted_sets::zunionstore(self, dest, keys, weights, aggregate)
.await?
.convert()
}
}
fn zmscore<R, K, V>(&self, key: K, members: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<MultipleValues> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(members);
commands::sorted_sets::zmscore(self, key, members).await?.convert()
}
}
}