use crate::{
commands,
error::RedisError,
interfaces::{ClientLike, RedisResult},
types::{FromRedis, MultipleStrings, RedisValue},
};
use bytes_utils::Str;
use std::convert::TryInto;
#[async_trait]
pub trait PubsubInterface: ClientLike + Sized {
async fn subscribe<S>(&self, channels: S) -> RedisResult<()>
where
S: Into<MultipleStrings> + Send,
{
into!(channels);
commands::pubsub::subscribe(self, channels).await
}
async fn unsubscribe<S>(&self, channels: S) -> RedisResult<()>
where
S: Into<MultipleStrings> + Send,
{
into!(channels);
commands::pubsub::unsubscribe(self, channels).await
}
async fn psubscribe<S>(&self, patterns: S) -> RedisResult<()>
where
S: Into<MultipleStrings> + Send,
{
into!(patterns);
commands::pubsub::psubscribe(self, patterns).await
}
async fn punsubscribe<S>(&self, patterns: S) -> RedisResult<()>
where
S: Into<MultipleStrings> + Send,
{
into!(patterns);
commands::pubsub::punsubscribe(self, patterns).await
}
async fn publish<R, S, V>(&self, channel: S, message: V) -> RedisResult<R>
where
R: FromRedis,
S: Into<Str> + Send,
V: TryInto<RedisValue> + Send,
V::Error: Into<RedisError> + Send,
{
into!(channel);
try_into!(message);
commands::pubsub::publish(self, channel, message).await?.convert()
}
async fn ssubscribe<C>(&self, channels: C) -> RedisResult<()>
where
C: Into<MultipleStrings> + Send,
{
into!(channels);
commands::pubsub::ssubscribe(self, channels).await
}
async fn sunsubscribe<C>(&self, channels: C) -> RedisResult<()>
where
C: Into<MultipleStrings> + Send,
{
into!(channels);
commands::pubsub::sunsubscribe(self, channels).await
}
async fn spublish<R, S, V>(&self, channel: S, message: V) -> RedisResult<R>
where
R: FromRedis,
S: Into<Str> + Send,
V: TryInto<RedisValue> + Send,
V::Error: Into<RedisError> + Send,
{
into!(channel);
try_into!(message);
commands::pubsub::spublish(self, channel, message).await?.convert()
}
async fn pubsub_channels<R, S>(&self, pattern: S) -> RedisResult<R>
where
R: FromRedis,
S: Into<Str> + Send,
{
into!(pattern);
commands::pubsub::pubsub_channels(self, pattern).await?.convert()
}
async fn pubsub_numpat<R>(&self) -> RedisResult<R>
where
R: FromRedis,
{
commands::pubsub::pubsub_numpat(self).await?.convert()
}
async fn pubsub_numsub<R, S>(&self, channels: S) -> RedisResult<R>
where
R: FromRedis,
S: Into<MultipleStrings> + Send,
{
into!(channels);
commands::pubsub::pubsub_numsub(self, channels).await?.convert()
}
async fn pubsub_shardchannels<R, S>(&self, pattern: S) -> RedisResult<R>
where
R: FromRedis,
S: Into<Str> + Send,
{
into!(pattern);
commands::pubsub::pubsub_shardchannels(self, pattern).await?.convert()
}
async fn pubsub_shardnumsub<R, S>(&self, channels: S) -> RedisResult<R>
where
R: FromRedis,
S: Into<MultipleStrings> + Send,
{
into!(channels);
commands::pubsub::pubsub_shardnumsub(self, channels).await?.convert()
}
}