use crate::{
commands,
error::Error,
interfaces::{ClientLike, FredResult},
types::{FromValue, Key, MultipleKeys, MultipleValues, Value},
};
use fred_macros::rm_send_if;
use futures::Future;
use std::convert::TryInto;
#[rm_send_if(feature = "glommio")]
pub trait SetsInterface: ClientLike + Sized {
fn sadd<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::sets::sadd(self, key, members).await?.convert()
}
}
fn scard<R, K>(&self, key: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sets::scard(self, key).await?.convert()
}
}
fn sdiff<R, K>(&self, keys: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::sets::sdiff(self, keys).await?.convert()
}
}
fn sdiffstore<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::sets::sdiffstore(self, dest, keys).await?.convert()
}
}
fn sinter<R, K>(&self, keys: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::sets::sinter(self, keys).await?.convert()
}
}
fn sinterstore<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::sets::sinterstore(self, dest, keys).await?.convert()
}
}
fn sismember<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::sets::sismember(self, key, member).await?.convert()
}
}
fn smismember<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::sets::smismember(self, key, members).await?.convert()
}
}
fn smembers<R, K>(&self, key: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::sets::smembers(self, key).await?.convert()
}
}
fn smove<R, S, D, V>(&self, source: S, dest: D, member: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Key> + Send,
D: Into<Key> + Send,
V: TryInto<Value> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(source, dest);
try_into!(member);
commands::sets::smove(self, source, dest, member).await?.convert()
}
}
fn spop<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::sets::spop(self, key, count).await?.convert()
}
}
fn srandmember<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::sets::srandmember(self, key, count).await?.convert()
}
}
fn srem<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::sets::srem(self, key, members).await?.convert()
}
}
fn sunion<R, K>(&self, keys: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<MultipleKeys> + Send,
{
async move {
into!(keys);
commands::sets::sunion(self, keys).await?.convert()
}
}
fn sunionstore<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::sets::sunionstore(self, dest, keys).await?.convert()
}
}
}