Skip to content

Commit

Permalink
change signature args
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemIsmagilov committed Dec 11, 2024
1 parent f8a64bd commit a0b2eaf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 40 deletions.
49 changes: 18 additions & 31 deletions src/commands/connection_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub trait ConnectionCommands<'a> {
/// ```
/// # use rustis::{
/// # client::Client,
/// # commands::{ConnectionCommands, SetInfoOptions},
/// # commands::{ConnectionCommands, ClientInfoAttribute},
/// # resp::cmd,
/// # Result,
/// # };
Expand All @@ -213,12 +213,11 @@ pub trait ConnectionCommands<'a> {
/// # async fn main() -> Result<()> {
/// # let client = Client::connect("127.0.0.1:6379").await?;
/// client
/// .client_setinfo(
/// SetInfoOptions::default()
/// .lib_name("rustis")
/// .lib_ver("0.13.3"),
/// )
/// .await?;
/// .client_setinfo(ClientInfoAttribute::LibName, "rustis")
/// .await?;
/// client
/// .client_setinfo(ClientInfoAttribute::LibVer, "0.13.3")
/// .await?;
///
/// let attrs: String = client.send(cmd("CLIENT").arg("INFO"), None).await?.to()?;
///
Expand All @@ -230,11 +229,12 @@ pub trait ConnectionCommands<'a> {
/// # See Also
/// [<https://redis.io/docs/latest/commands/client-setinfo/>](https://redis.io/docs/latest/commands/client-setinfo/)
#[must_use]
fn client_setinfo(self, options: SetInfoOptions) -> PreparedCommand<'a, Self, ()>
fn client_setinfo<I>(self, attr: ClientInfoAttribute, info: I) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
I: SingleArg,
{
prepare_command(self, cmd("CLIENT").arg("SETINFO").arg(options))
prepare_command(self, cmd("CLIENT").arg("SETINFO").arg(attr).arg(info))
}

/// This command enables the tracking feature of the Redis server,
Expand Down Expand Up @@ -961,30 +961,17 @@ impl ToArgs for PingOptions {
}
}

//Options for the [`set_info`](ConnectionCommands::set_info) cpmmand.
#[derive(Default)]
pub struct SetInfoOptions {
command_args: CommandArgs,
// Info options for the [`client_setinfo`](ConnectionCommands::client_info) command.
pub enum ClientInfoAttribute {
LibName,
LibVer,
}

impl SetInfoOptions {
#[must_use]
pub fn lib_name<N: SingleArg>(mut self, lib_name: N) -> Self {
Self {
command_args: self.command_args.arg("LIB-NAME").arg(lib_name).build(),
}
}

#[must_use]
pub fn lib_ver<V: SingleArg>(mut self, lib_ver: V) -> Self {
Self {
command_args: self.command_args.arg("LIB-VER").arg(lib_ver).build(),
}
}
}

impl ToArgs for SetInfoOptions {
impl ToArgs for ClientInfoAttribute {
fn write_args(&self, args: &mut CommandArgs) {
args.arg(&self.command_args);
args.arg(match self {
ClientInfoAttribute::LibName => "LIB-NAME",
ClientInfoAttribute::LibVer => "LIB-VER",
});
}
}
17 changes: 8 additions & 9 deletions src/tests/connection_commands.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{
client::{BatchPreparedCommand, Client, ClientPreparedCommand},
commands::{
ClientCachingMode, ClientKillOptions, ClientListOptions, ClientPauseMode, ClientReplyMode,
ClientTrackingOptions, ClientTrackingStatus, ClientUnblockMode, ConnectionCommands,
FlushingMode, GenericCommands, HelloOptions, PingOptions, ServerCommands, SetInfoOptions,
StringCommands,
ClientCachingMode, ClientInfoAttribute, ClientKillOptions, ClientListOptions,
ClientPauseMode, ClientReplyMode, ClientTrackingOptions, ClientTrackingStatus,
ClientUnblockMode, ConnectionCommands, FlushingMode, GenericCommands, HelloOptions,
PingOptions, ServerCommands, StringCommands,
},
network::spawn,
resp::cmd,
Expand Down Expand Up @@ -198,11 +198,10 @@ async fn client_setname_getname() -> Result<()> {
async fn client_setinfo() -> Result<()> {
let client = get_test_client().await?;
client
.client_setinfo(
SetInfoOptions::default()
.lib_name("rustis")
.lib_ver("0.13.3"),
)
.client_setinfo(ClientInfoAttribute::LibName, "rustis")
.await?;
client
.client_setinfo(ClientInfoAttribute::LibVer, "0.13.3")
.await?;

let attrs: String = client.send(cmd("CLIENT").arg("INFO"), None).await?.to()?;
Expand Down

0 comments on commit a0b2eaf

Please sign in to comment.