Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement client set #11

Merged
merged 11 commits into from
Mar 28, 2020
Merged

implement client set #11

merged 11 commits into from
Mar 28, 2020

Conversation

EverlastingBugstopper
Copy link
Collaborator

@EverlastingBugstopper EverlastingBugstopper commented Mar 3, 2020

still work to be done here but it's a start. right now this commit
contains logic to handle cargo run --bin client set key value and
nothing else

TODO:

  • handle expiration (EX seconds) (PX milliseconds)
  • clean up code layout?

i have an open question about usage and specifying EX/PX here, and still need to send the proper frames when our duration argument is sent

still work to be done here but it's a start. right now this commit
contains logic to handle `cargo run --bin client set key value` and
nothing else
@EverlastingBugstopper EverlastingBugstopper force-pushed the avery/tracing branch 2 times, most recently from eda7343 to 2b6b19e Compare March 3, 2020 23:14
@EverlastingBugstopper EverlastingBugstopper changed the base branch from avery/tracing to master March 17, 2020 16:26
src/cmd/set.rs Outdated
@@ -50,4 +67,12 @@ impl Set {
debug!(?response);
dst.write_frame(&response).await
}

pub(crate) fn get_frame(self) -> Frame {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idiomatically, this probably should be named into_frame.

src/client.rs Outdated
unimplemented!();
pub async fn set(&mut self, opts: Set) -> io::Result<()> {
let frame = Command::Set(opts).to_frame()?;
self.conn.write_frame(&frame).await
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we probably should validate the response?

"unexpected response from server",
));
if let Some(response) = response {
match response {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably want to have a fn that tries to convert a frame into the various types. Then you can do response.try_into_string() or something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting thought - seems probably worth a separate PR

src/client.rs Outdated
Ok(self.conn.write_frame(&frame).await?)
self.conn.write_frame(&frame).await?;
let response = self.conn.read_frame().await?;
let unknown_error = Box::new(Error::new(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid unconditionally allocating here.

src/client.rs Outdated
if response == "OK" {
Ok(())
} else {
Err(unknown_error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Err(unknown_error)
Err("unexpected response from server".into())

This should work. The error message could be set to a const too to avoid duplicating it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 TIL!

@EverlastingBugstopper EverlastingBugstopper changed the title wip: implement client set implement client set Mar 26, 2020
Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna merge as is 👍 can polish in further PRs.

@carllerche carllerche merged commit 7bd7086 into master Mar 28, 2020
carllerche added a commit that referenced this pull request Mar 30, 2020
Continuation of #11. Refines the client structure and implements GET.

`clap` is decoupled from the lib code. This is done to avoid any CLI
parsing concerns to leak into the lib. The main motivation for this is
to allow the reader to focus on Tokio concerns and not CLI parsing
concerns.
carllerche added a commit that referenced this pull request Apr 1, 2020
Continuation of #11. Refines the client structure and implements GET.

`clap` is decoupled from the lib code. This is done to avoid any CLI
parsing concerns to leak into the lib. The main motivation for this is
to allow the reader to focus on Tokio concerns and not CLI parsing
concerns.
@carllerche carllerche deleted the avery/client-set branch April 20, 2020 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants