use crate::{
commands,
error::Error,
interfaces::{ClientLike, FredResult},
types::{FromValue, Map, SentinelFailureKind, Value},
};
use bytes_utils::Str;
use fred_macros::rm_send_if;
use futures::Future;
use std::{convert::TryInto, net::IpAddr};
#[rm_send_if(feature = "glommio")]
pub trait SentinelInterface: ClientLike + Sized {
fn ckquorum<R, N>(&self, name: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::ckquorum(self, name).await?.convert()
}
}
fn flushconfig<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::sentinel::flushconfig(self).await?.convert() }
}
fn failover<R, N>(&self, name: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::failover(self, name).await?.convert()
}
}
fn get_master_addr_by_name<R, N>(&self, name: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::get_master_addr_by_name(self, name).await?.convert()
}
}
fn info_cache<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::sentinel::info_cache(self).await?.convert() }
}
fn master<R, N>(&self, name: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::master(self, name).await?.convert()
}
}
fn masters<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::sentinel::masters(self).await?.convert() }
}
fn monitor<R, N>(&self, name: N, ip: IpAddr, port: u16, quorum: u32) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::monitor(self, name, ip, port, quorum)
.await?
.convert()
}
}
fn myid<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::sentinel::myid(self).await?.convert() }
}
fn pending_scripts<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::sentinel::pending_scripts(self).await?.convert() }
}
fn remove<R, N>(&self, name: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::remove(self, name).await?.convert()
}
}
fn replicas<R, N>(&self, name: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::replicas(self, name).await?.convert()
}
}
fn sentinels<R, N>(&self, name: N) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::sentinels(self, name).await?.convert()
}
}
fn set<R, N, V>(&self, name: N, args: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
N: Into<Str> + Send,
V: TryInto<Map> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(name);
try_into!(args);
commands::sentinel::set(self, name, args).await?.convert()
}
}
fn simulate_failure<R>(&self, kind: SentinelFailureKind) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::sentinel::simulate_failure(self, kind).await?.convert() }
}
fn reset<R, P>(&self, pattern: P) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
P: Into<Str> + Send,
{
async move {
into!(pattern);
commands::sentinel::reset(self, pattern).await?.convert()
}
}
fn config_get<R, K>(&self, name: K) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Str> + Send,
{
async move {
into!(name);
commands::sentinel::config_get(self, name).await?.convert()
}
}
fn config_set<R, K, V>(&self, name: K, value: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
K: Into<Str> + Send,
V: TryInto<Value> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(name);
try_into!(value);
commands::sentinel::config_set(self, name, value).await?.convert()
}
}
}