use crate::{
commands,
error::Error,
interfaces::{ClientLike, FredResult},
types::{
lists::{LMoveDirection, ListLocation},
FromValue,
Key,
Limit,
MultipleKeys,
MultipleStrings,
MultipleValues,
SortOrder,
Value,
},
};
use bytes_utils::Str;
use fred_macros::rm_send_if;
use futures::Future;
use std::convert::TryInto;
#[rm_send_if(feature = "glommio")]
pub trait ListInterface: ClientLike + Sized {
fn blmpop<R, K>(
&self,
timeout: f64,
keys: K,
direction: LMoveDirection,
count: Option<i64>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::lists::blmpop(self, timeout, keys, direction, count)
.await?
.convert()
}
}
fn blpop<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::lists::blpop(self, keys, timeout).await?.convert()
}
}
fn brpop<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::lists::brpop(self, keys, timeout).await?.convert()
}
}
fn brpoplpush<R, S, D>(&self, source: S, destination: D, timeout: f64) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Key> + Send,
D: Into<Key> + Send,
{
async move {
into!(source, destination);
commands::lists::brpoplpush(self, source, destination, timeout)
.await?
.convert()
}
}
fn blmove<R, S, D>(
&self,
source: S,
destination: D,
source_direction: LMoveDirection,
destination_direction: LMoveDirection,
timeout: f64,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Key> + Send,
D: Into<Key> + Send,
{
async move {
into!(source, destination);
commands::lists::blmove(
self,
source,
destination,
source_direction,
destination_direction,
timeout,
)
.await?
.convert()
}
}
fn lmpop<R, K>(
&self,
keys: K,
direction: LMoveDirection,
count: Option<i64>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::lists::lmpop(self, keys, direction, count).await?.convert()
}
}
fn lindex<R, K>(&self, key: K, index: i64) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::lists::lindex(self, key, index).await?.convert()
}
}
fn linsert<R, K, P, V>(
&self,
key: K,
location: ListLocation,
pivot: P,
element: V,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
P: TryInto<Value> + Send,
P::Error: Into<Error> + Send,
V: TryInto<Value> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(pivot, element);
commands::lists::linsert(self, key, location, pivot, element)
.await?
.convert()
}
}
fn llen<R, K>(&self, key: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::lists::llen(self, key).await?.convert()
}
}
fn lpop<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::lists::lpop(self, key, count).await?.convert()
}
}
fn lpos<R, K, V>(
&self,
key: K,
element: V,
rank: Option<i64>,
count: Option<i64>,
maxlen: Option<i64>,
) -> 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!(element);
commands::lists::lpos(self, key, element, rank, count, maxlen)
.await?
.convert()
}
}
fn lpush<R, K, V>(&self, key: K, elements: 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!(elements);
commands::lists::lpush(self, key, elements).await?.convert()
}
}
fn lpushx<R, K, V>(&self, key: K, elements: 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!(elements);
commands::lists::lpushx(self, key, elements).await?.convert()
}
}
fn lrange<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::lists::lrange(self, key, start, stop).await?.convert()
}
}
fn lrem<R, K, V>(&self, key: K, count: i64, element: 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!(element);
commands::lists::lrem(self, key, count, element).await?.convert()
}
}
fn lset<R, K, V>(&self, key: K, index: i64, element: 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!(element);
commands::lists::lset(self, key, index, element).await?.convert()
}
}
fn ltrim<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::lists::ltrim(self, key, start, stop).await?.convert()
}
}
fn rpop<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::lists::rpop(self, key, count).await?.convert()
}
}
fn rpoplpush<R, S, D>(&self, source: S, dest: D) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Key> + Send,
D: Into<Key> + Send,
{
async move {
into!(source, dest);
commands::lists::rpoplpush(self, source, dest).await?.convert()
}
}
fn lmove<R, S, D>(
&self,
source: S,
dest: D,
source_direction: LMoveDirection,
dest_direction: LMoveDirection,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Key> + Send,
D: Into<Key> + Send,
{
async move {
into!(source, dest);
commands::lists::lmove(self, source, dest, source_direction, dest_direction)
.await?
.convert()
}
}
fn rpush<R, K, V>(&self, key: K, elements: 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!(elements);
commands::lists::rpush(self, key, elements).await?.convert()
}
}
fn rpushx<R, K, V>(&self, key: K, elements: 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!(elements);
commands::lists::rpushx(self, key, elements).await?.convert()
}
}
fn sort<R, K, S>(
&self,
key: K,
by: Option<Str>,
limit: Option<Limit>,
get: S,
order: Option<SortOrder>,
alpha: bool,
store: Option<Key>,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
S: Into<MultipleStrings> + Send,
{
async move {
into!(key, get);
commands::lists::sort(self, key, by, limit, get, order, alpha, store)
.await?
.convert()
}
}
fn sort_ro<R, K, S>(
&self,
key: K,
by: Option<Str>,
limit: Option<Limit>,
get: S,
order: Option<SortOrder>,
alpha: bool,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
S: Into<MultipleStrings> + Send,
{
async move {
into!(key, get);
commands::lists::sort_ro(self, key, by, limit, get, order, alpha)
.await?
.convert()
}
}
}