Skip to content

Commit

Permalink
add ACL HELP (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemIsmagilov authored Nov 9, 2024
1 parent 02d5b1a commit 1cc798f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
41 changes: 37 additions & 4 deletions src/commands/server_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,38 @@ pub trait ServerCommands<'a> {
prepare_command(self, cmd("ACL").arg("GETUSER").arg(username))
}

/// The command returns a helpful text describing the different ACL subcommands.
///
/// # Return
/// An array of strings.
///
/// # Example
/// ```
/// # use rustis::{
/// # client::{Client, ClientPreparedCommand},
/// # commands::{FlushingMode, GetExOptions, GenericCommands, ServerCommands, StringCommands},
/// # resp::cmd,
/// # 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<String> = client.acl_help().await?;
/// assert!(result.iter().any(|e| e == "HELP"));
/// # Ok(())
/// # }
/// ```
/// # See Also
/// [<https://redis.io/commands/acl-help/>](https://redis.io/commands/acl-help/)
fn acl_help(self) -> PreparedCommand<'a, Self, Vec<String>>
where
Self: Sized,
{
prepare_command(self, cmd("ACL").arg("HELP"))
}

/// The command shows the currently active ACL rules in the Redis server.
///
/// # Return
Expand Down Expand Up @@ -864,8 +896,7 @@ pub enum FlushingMode {
impl ToArgs for FlushingMode {
fn write_args(&self, args: &mut CommandArgs) {
match self {
FlushingMode::Default => {
}
FlushingMode::Default => {}
FlushingMode::Async => {
args.arg("ASYNC");
}
Expand Down Expand Up @@ -1928,10 +1959,12 @@ impl<'de> Deserialize<'de> for RoleResult {

match role {
"master" => {
let Some(master_replication_offset): Option<usize> = seq.next_element()? else {
let Some(master_replication_offset): Option<usize> = seq.next_element()?
else {
return Err(de::Error::invalid_length(1, &"more elements in sequence"));
};
let Some(replica_infos): Option<Vec<ReplicaInfo>> = seq.next_element()? else {
let Some(replica_infos): Option<Vec<ReplicaInfo>> = seq.next_element()?
else {
return Err(de::Error::invalid_length(2, &"more elements in sequence"));
};
Ok(RoleResult::Master {
Expand Down
16 changes: 15 additions & 1 deletion src/tests/server_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use crate::{
},
resp::{cmd, Value},
spawn,
tests::{get_default_config, get_sentinel_test_client, get_test_client, get_test_client_with_config},
tests::{
get_default_config, get_sentinel_test_client, get_test_client, get_test_client_with_config,
},
Error, RedisError, RedisErrorKind, Result,
};
use futures_util::StreamExt;
Expand Down Expand Up @@ -118,6 +120,18 @@ async fn acl_getuser() -> Result<()> {
Ok(())
}

#[cfg_attr(feature = "tokio-runtime", tokio::test)]
#[cfg_attr(feature = "async-std-runtime", async_std::test)]
#[serial]
async fn acl_help() -> Result<()> {
let client = get_test_client().await?;

let result: Vec<String> = client.acl_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]
Expand Down

0 comments on commit 1cc798f

Please sign in to comment.