1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
use crate::{
resp::{FromValue, Value},
Command, Result,
};
use futures::Future;
use std::pin::Pin;
pub trait CommandSend {
/// Send an arbitrary command to the server.
///
/// This is used primarily intended for implementing high level commands API
/// but may also be used to provide access to new features that lack a direct API.
///
/// # Arguments
/// * `name` - Command name in uppercase.
/// * `args` - Command arguments which can be provided as arrays (up to 4 elements) or vectors of [BulkString](crate::resp::BulkString).
///
/// # Example
/// ```ignore
/// let connection = ConnectionMultiplexer::connect("127.0.0.1:6379").await?;
/// let database = connection.get_default_database();
///
/// let values: Vec<String> = database
/// .send(cmd("MGET").arg("key1").arg("key2").arg("key3").arg("key4"))
/// .await?
/// .into()?;
/// ```
fn send(&self, command: Command) -> Pin<Box<dyn Future<Output = Result<Value>> + Send + '_>>;
fn send_into<T: FromValue>(
&self,
command: Command,
) -> Pin<Box<dyn Future<Output = Result<T>> + Send + '_>> {
let fut = self.send(command);
Box::pin(async move { fut.await?.into() })
}
fn send_into_tuple_vec<T: FromValue, U: FromValue>(
&self,
command: Command,
) -> Pin<Box<dyn Future<Output = Result<Vec<(T, U)>>> + Send + '_>> {
let fut = self.send(command);
Box::pin(async move { fut.await?.into_tuple_vec() })
}
}