use crate::{
commands,
error::RedisError,
interfaces::{ClientLike, RedisResult},
types::{FromRedis, MultipleKeys, RedisKey, RedisMap, RedisValue},
};
use fred_macros::rm_send_if;
use futures::Future;
use std::convert::TryInto;
#[rm_send_if(feature = "glommio")]
pub trait HashesInterface: ClientLike + Sized {
fn hgetall<R, K>(&self, key: K) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
F: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
F: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
F: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
F: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
{
async move {
into!(key);
commands::hashes::hkeys(self, key).await?.convert()
}
}
fn hlen<R, K>(&self, key: K) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
V: TryInto<RedisMap> + Send,
V::Error: Into<RedisError> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
V: TryInto<RedisMap> + Send,
V::Error: Into<RedisError> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
F: Into<RedisKey> + Send,
V: TryInto<RedisValue> + Send,
V::Error: Into<RedisError> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + 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 = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
F: Into<RedisKey> + Send,
{
async move {
into!(key, field);
commands::hashes::hstrlen(self, key, field).await?.convert()
}
}
fn hvals<R, K>(&self, key: K) -> impl Future<Output = RedisResult<R>> + Send
where
R: FromRedis,
K: Into<RedisKey> + Send,
{
async move {
into!(key);
commands::hashes::hvals(self, key).await?.convert()
}
}
}