use crate::{
commands,
error::Error,
interfaces::{ClientLike, FredResult},
types::{
scripts::{FnPolicy, ScriptDebugFlag},
FromValue,
MultipleKeys,
MultipleStrings,
MultipleValues,
},
};
use bytes::Bytes;
use bytes_utils::Str;
use fred_macros::rm_send_if;
use futures::Future;
use std::convert::TryInto;
#[rm_send_if(feature = "glommio")]
pub trait LuaInterface: ClientLike + Sized {
fn script_load<R, S>(&self, script: S) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Str> + Send,
{
async move {
into!(script);
commands::lua::script_load(self, script).await?.convert()
}
}
#[cfg(feature = "sha-1")]
#[cfg_attr(docsrs, doc(cfg(feature = "sha-1")))]
fn script_load_cluster<R, S>(&self, script: S) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Str> + Send,
{
async move {
into!(script);
commands::lua::script_load_cluster(self, script).await?.convert()
}
}
fn script_kill(&self) -> impl Future<Output = FredResult<()>> + Send {
async move { commands::lua::script_kill(self).await }
}
fn script_kill_cluster(&self) -> impl Future<Output = FredResult<()>> + Send {
async move { commands::lua::script_kill_cluster(self).await }
}
fn script_flush(&self, r#async: bool) -> impl Future<Output = FredResult<()>> + Send {
async move { commands::lua::script_flush(self, r#async).await }
}
fn script_flush_cluster(&self, r#async: bool) -> impl Future<Output = FredResult<()>> + Send {
async move { commands::lua::script_flush_cluster(self, r#async).await }
}
fn script_exists<R, H>(&self, hashes: H) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
H: Into<MultipleStrings> + Send,
{
async move {
into!(hashes);
commands::lua::script_exists(self, hashes).await?.convert()
}
}
fn script_debug(&self, flag: ScriptDebugFlag) -> impl Future<Output = FredResult<()>> + Send {
async move { commands::lua::script_debug(self, flag).await }
}
fn evalsha<R, S, K, V>(&self, hash: S, keys: K, args: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Str> + Send,
K: Into<MultipleKeys> + Send,
V: TryInto<MultipleValues> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(hash, keys);
try_into!(args);
commands::lua::evalsha(self, hash, keys, args).await?.convert()
}
}
fn eval<R, S, K, V>(&self, script: S, keys: K, args: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Str> + Send,
K: Into<MultipleKeys> + Send,
V: TryInto<MultipleValues> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(script, keys);
try_into!(args);
commands::lua::eval(self, script, keys, args).await?.convert()
}
}
}
#[rm_send_if(feature = "glommio")]
pub trait FunctionInterface: ClientLike + Sized {
fn fcall<R, F, K, V>(&self, func: F, keys: K, args: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
F: Into<Str> + Send,
K: Into<MultipleKeys> + Send,
V: TryInto<MultipleValues> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(func);
try_into!(keys, args);
commands::lua::fcall(self, func, keys, args).await?.convert()
}
}
fn fcall_ro<R, F, K, V>(&self, func: F, keys: K, args: V) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
F: Into<Str> + Send,
K: Into<MultipleKeys> + Send,
V: TryInto<MultipleValues> + Send,
V::Error: Into<Error> + Send,
{
async move {
into!(func);
try_into!(keys, args);
commands::lua::fcall_ro(self, func, keys, args).await?.convert()
}
}
fn function_delete<R, S>(&self, library_name: S) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Str> + Send,
{
async move {
into!(library_name);
commands::lua::function_delete(self, library_name).await?.convert()
}
}
fn function_delete_cluster<S>(&self, library_name: S) -> impl Future<Output = FredResult<()>> + Send
where
S: Into<Str> + Send,
{
async move {
into!(library_name);
commands::lua::function_delete_cluster(self, library_name).await
}
}
fn function_dump<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::lua::function_dump(self).await?.convert() }
}
fn function_flush<R>(&self, r#async: bool) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::lua::function_flush(self, r#async).await?.convert() }
}
fn function_flush_cluster(&self, r#async: bool) -> impl Future<Output = FredResult<()>> + Send {
async move { commands::lua::function_flush_cluster(self, r#async).await }
}
fn function_kill<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::lua::function_kill(self).await?.convert() }
}
fn function_list<R, S>(&self, library_name: Option<S>, withcode: bool) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Str> + Send,
{
async move {
let library_name = library_name.map(|l| l.into());
commands::lua::function_list(self, library_name, withcode)
.await?
.convert()
}
}
fn function_load<R, S>(&self, replace: bool, code: S) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Str> + Send,
{
async move {
into!(code);
commands::lua::function_load(self, replace, code).await?.convert()
}
}
fn function_load_cluster<R, S>(&self, replace: bool, code: S) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
S: Into<Str> + Send,
{
async move {
into!(code);
commands::lua::function_load_cluster(self, replace, code)
.await?
.convert()
}
}
fn function_restore<R, B, P>(&self, serialized: B, policy: P) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
B: Into<Bytes> + Send,
P: TryInto<FnPolicy> + Send,
P::Error: Into<Error> + Send,
{
async move {
into!(serialized);
try_into!(policy);
commands::lua::function_restore(self, serialized, policy)
.await?
.convert()
}
}
fn function_restore_cluster<B, P>(&self, serialized: B, policy: P) -> impl Future<Output = FredResult<()>> + Send
where
B: Into<Bytes> + Send,
P: TryInto<FnPolicy> + Send,
P::Error: Into<Error> + Send,
{
async move {
into!(serialized);
try_into!(policy);
commands::lua::function_restore_cluster(self, serialized, policy).await
}
}
fn function_stats<R>(&self) -> impl Future<Output = FredResult<R>> + Send
where
R: FromValue,
{
async move { commands::lua::function_stats(self).await?.convert() }
}
}