use crate::{
commands,
error::Error,
interfaces::{ClientLike, FredResult},
types::{config::Server, FromValue, Value},
};
use fred_macros::rm_send_if;
use futures::Future;
#[rm_send_if(feature = "glommio")]
pub trait ServerInterface: ClientLike {
fn bgrewriteaof<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::server::bgrewriteaof(self).await?.convert() }
}
fn bgsave<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::server::bgsave(self).await?.convert() }
}
fn dbsize<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::server::dbsize(self).await?.convert() }
}
fn select<I>(&self, index: I) -> impl Future<Output = FredResult<()>> + Send
where
I: TryInto<Value> + Send,
I::Error: Into<Error> + Send,
{
async move {
try_into!(index);
commands::server::select(self, index).await?.convert()
}
}
fn failover(
&self,
to: Option<(String, u16)>,
force: bool,
abort: bool,
timeout: Option<u32>,
) -> impl Future<Output = FredResult<()>> + Send {
async move { commands::server::failover(self, to, force, abort, timeout).await }
}
fn lastsave<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::server::lastsave(self).await?.convert() }
}
fn wait<R>(&self, numreplicas: i64, timeout: i64) -> impl Future<Output = Result<R, Error>> + Send
where
R: FromValue,
{
async move { commands::server::wait(self, numreplicas, timeout).await?.convert() }
}
fn sentinel_primary(&self) -> Option<Server> {
self.inner().server_state.read().kind.sentinel_primary()
}
fn sentinel_nodes(&self) -> Option<Vec<Server>> {
let inner = self.inner();
inner.server_state.read().kind.read_sentinel_nodes(&inner.config.server)
}
}