use crate::{
commands,
error::Error,
interfaces::{ClientLike, FredResult},
types::{FromValue, Key, Map, MultipleKeys, Value},
};
use fred_macros::rm_send_if;
use futures::Future;
use std::convert::TryInto;
#[cfg(feature = "i-hexpire")]
use crate::types::ExpireOptions;
#[rm_send_if(feature = "glommio")]
pub trait HashesInterface: ClientLike + Sized {
fn hgetall<R, K>(&self, key: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::hashes::hgetall(self, key).await?.convert()
}
}
fn hdel<R, K, F>(&self, key: K, fields: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hdel(self, key, fields).await?.convert()
}
}
fn hexists<R, K, F>(&self, key: K, field: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<Key> + Send,
{
async move {
into!(key, field);
commands::hashes::hexists(self, key, field).await?.convert()
}
}
fn hget<R, K, F>(&self, key: K, field: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<Key> + Send,
{
async move {
into!(key, field);
commands::hashes::hget(self, key, field).await?.convert()
}
}
fn hincrby<R, K, F>(&self, key: K, field: F, increment: i64) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<Key> + Send,
{
async move {
into!(key, field);
commands::hashes::hincrby(self, key, field, increment).await?.convert()
}
}
fn hincrbyfloat<R, K, F>(&self, key: K, field: F, increment: f64) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<Key> + Send,
{
async move {
into!(key, field);
commands::hashes::hincrbyfloat(self, key, field, increment)
.await?
.convert()
}
}
fn hkeys<R, K>(&self, key: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::hashes::hkeys(self, key).await?.convert()
}
}
fn hlen<R, K>(&self, key: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::hashes::hlen(self, key).await?.convert()
}
}
fn hmget<R, K, F>(&self, key: K, fields: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hmget(self, key, fields).await?.convert()
}
}
fn hmset<R, K, V>(&self, key: K, values: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<Map> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(values);
commands::hashes::hmset(self, key, values).await?.convert()
}
}
fn hset<R, K, V>(&self, key: K, values: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
V: TryInto<Map> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key);
try_into!(values);
commands::hashes::hset(self, key, values).await?.convert()
}
}
fn hsetnx<R, K, F, V>(&self, key: K, field: F, value: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<Key> + Send,
V: TryInto<Value> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(key, field);
try_into!(value);
commands::hashes::hsetnx(self, key, field, value).await?.convert()
}
}
fn hrandfield<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::hashes::hrandfield(self, key, count).await?.convert()
}
}
fn hstrlen<R, K, F>(&self, key: K, field: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<Key> + Send,
{
async move {
into!(key, field);
commands::hashes::hstrlen(self, key, field).await?.convert()
}
}
fn hvals<R, K>(&self, key: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
{
async move {
into!(key);
commands::hashes::hvals(self, key).await?.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn httl<R, K, F>(&self, key: K, fields: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::httl(self, key, fields).await?.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn hexpire<R, K, F>(
&self,
key: K,
seconds: i64,
options: Option<ExpireOptions>,
fields: F,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hexpire(self, key, seconds, options, fields)
.await?
.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn hexpire_at<R, K, F>(
&self,
key: K,
time: i64,
options: Option<ExpireOptions>,
fields: F,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hexpire_at(self, key, time, options, fields)
.await?
.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn hexpire_time<R, K, F>(&self, key: K, fields: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hexpire_time(self, key, fields).await?.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn hpttl<R, K, F>(&self, key: K, fields: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hpttl(self, key, fields).await?.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn hpexpire<R, K, F>(
&self,
key: K,
milliseconds: i64,
options: Option<ExpireOptions>,
fields: F,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hpexpire(self, key, milliseconds, options, fields)
.await?
.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn hpexpire_at<R, K, F>(
&self,
key: K,
time: i64,
options: Option<ExpireOptions>,
fields: F,
) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hpexpire_at(self, key, time, options, fields)
.await?
.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn hpexpire_time<R, K, F>(&self, key: K, fields: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hpexpire_time(self, key, fields).await?.convert()
}
}
#[cfg(feature = "i-hexpire")]
#[cfg_attr(docsrs, doc(cfg(feature = "i-hexpire")))]
fn hpersist<R, K, F>(&self, key: K, fields: F) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Key> + Send,
F: Into<MultipleKeys> + Send,
{
async move {
into!(key, fields);
commands::hashes::hpersist(self, key, fields).await?.convert()
}
}
}