Skip to content

Commit

Permalink
Allow client binary to provide context on put
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmgleite committed Jul 11, 2024
1 parent 13ff766 commit b12cd90
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode
target
concurrent_put.sh
12 changes: 10 additions & 2 deletions src/bin/db_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ enum Commands {

#[arg(short)]
value: Bytes,

#[arg(short)]
context: Option<String>,
},
#[command()]
JoinCluster {
Expand Down Expand Up @@ -73,12 +76,17 @@ async fn main() -> anyhow::Result<()> {
let payload = serde_json::to_string(&response)?;
stdout.write_all(payload.as_bytes()).await?;
}
Commands::Put { port, key, value } => {
Commands::Put {
port,
key,
value,
context,
} => {
let mut client = DbClient::new(format!("127.0.0.1:{}", port));
client.connect().await?;
// FIXME: The API has to receive the CRC instead of computing it...
let value = Value::new_unchecked(value);
let response = client.put(key, value, None, false).await?;
let response = client.put(key, value, context, false).await?;
let mut stdout = tokio::io::stdout();
let payload = serde_json::to_string(&response)?;
stdout.write_all(payload.as_bytes()).await?;
Expand Down
2 changes: 1 addition & 1 deletion src/client/db_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl DbClient {
where
F: Future,
{
if let Ok(_) = REQUEST_ID.try_with(|request_id| request_id.clone()) {
if let Ok(_) = REQUEST_ID.try_with(|_| ()) {
f.await
} else {
REQUEST_ID.scope(generate_request_id(), f).await
Expand Down

0 comments on commit b12cd90

Please sign in to comment.