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