implement client ping (#108)

This commit is contained in:
Kim Chan
2022-08-25 17:10:32 +08:00
committed by GitHub
parent d3826795af
commit c1c3bcb465
4 changed files with 84 additions and 1 deletions

View File

@@ -26,6 +26,10 @@ struct Cli {
#[derive(Subcommand, Debug)]
enum Command {
Ping {
/// Message to ping
msg: Option<String>,
},
/// Get the value of key.
Get {
/// Name of key to get
@@ -85,6 +89,14 @@ async fn main() -> mini_redis::Result<()> {
// Process the requested command
match cli.command {
Command::Ping { msg } => {
let value = client.ping(msg).await?;
if let Ok(string) = str::from_utf8(&value) {
println!("\"{}\"", string);
} else {
println!("{:?}", value);
}
}
Command::Get { key } => {
if let Some(value) = client.get(&key).await? {
if let Ok(string) = str::from_utf8(&value) {