From 02bc8dca77ccd7fb8dea0a46eccef1e5728837fd Mon Sep 17 00:00:00 2001 From: ArtemIsmagilov <118372045+ArtemIsmagilov@users.noreply.github.com> Date: Wed, 25 Dec 2024 13:03:35 +0400 Subject: [PATCH] impl memory help, high level command (#91) --- src/commands/server_commands.rs | 33 +++++++++++++++++++++++++++++++++ src/tests/server_commands.rs | 12 ++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/commands/server_commands.rs b/src/commands/server_commands.rs index 9d48b0e..0a87784 100644 --- a/src/commands/server_commands.rs +++ b/src/commands/server_commands.rs @@ -835,6 +835,39 @@ pub trait ServerCommands<'a> { prepare_command(self, cmd("MEMORY").arg("DOCTOR")) } + /// The command returns a helpful text describing the different MEMORY subcommands. + /// + /// # Return + /// An array of strings. + /// + /// # Example + /// ``` + /// # use rustis::{ + /// # client::Client, + /// # commands::ServerCommands, + /// # Result, + /// # }; + /// # + /// # #[cfg_attr(feature = "tokio-runtime", tokio::main)] + /// # #[cfg_attr(feature = "async-std-runtime", async_std::main)] + /// # async fn main() -> Result<()> { + /// # let client = Client::connect("127.0.0.1:6379").await?; + /// let result: Vec = client.memory_help().await?; + /// assert!(result.iter().any(|e| e == "HELP")); + /// # Ok(()) + /// # } + /// ``` + /// + /// # See Also + /// [](https://redis.io/commands/memory-help/) + #[must_use] + fn memory_help(self) -> PreparedCommand<'a, Self, Vec> + where + Self: Sized, + { + prepare_command(self, cmd("MEMORY").arg("HELP")) + } + /// This command provides an internal statistics report from the memory allocator. /// /// # Return diff --git a/src/tests/server_commands.rs b/src/tests/server_commands.rs index 0ae25bb..daa11c7 100644 --- a/src/tests/server_commands.rs +++ b/src/tests/server_commands.rs @@ -850,6 +850,18 @@ async fn memory_doctor() -> Result<()> { Ok(()) } +#[cfg_attr(feature = "tokio-runtime", tokio::test)] +#[cfg_attr(feature = "async-std-runtime", async_std::test)] +#[serial] +async fn memory_help() -> Result<()> { + let client = get_test_client().await?; + + let result = client.memory_help().await?; + assert!(result.iter().any(|e| e == "HELP")); + + Ok(()) +} + #[cfg_attr(feature = "tokio-runtime", tokio::test)] #[cfg_attr(feature = "async-std-runtime", async_std::test)] #[serial]