diff --git a/worterbuch-cli/src/bin/wbpdel.rs b/worterbuch-cli/src/bin/wbpdel.rs index e5e0009..84028d6 100644 --- a/worterbuch-cli/src/bin/wbpdel.rs +++ b/worterbuch-cli/src/bin/wbpdel.rs @@ -54,6 +54,9 @@ struct Args { /// Set a client name on the server #[arg(short, long)] name: Option, + /// Don't return deleted values + #[arg(short, long)] + quiet: bool, } #[tokio::main(flavor = "current_thread")] async fn main() -> Result<()> { @@ -125,7 +128,7 @@ async fn run(subsys: SubsystemHandle) -> Result<()> { } }, recv = next_item(&mut rx, done) => match recv { - Some(key ) => trans_id = wb.pdelete_async(key).await?, + Some(key ) => trans_id = wb.pdelete_async(key, args.quiet).await?, None => done = true, }, } diff --git a/worterbuch-client/src/lib.rs b/worterbuch-client/src/lib.rs index 59bb37f..da822c8 100644 --- a/worterbuch-client/src/lib.rs +++ b/worterbuch-client/src/lib.rs @@ -76,8 +76,8 @@ pub(crate) enum Command { PGetAsync(Key, oneshot::Sender), Delete(Key, oneshot::Sender<(Option, TransactionId)>), DeleteAsync(Key, oneshot::Sender), - PDelete(Key, oneshot::Sender<(KeyValuePairs, TransactionId)>), - PDeleteAsync(Key, oneshot::Sender), + PDelete(Key, bool, oneshot::Sender<(KeyValuePairs, TransactionId)>), + PDeleteAsync(Key, bool, oneshot::Sender), Ls( Option, oneshot::Sender<(Vec, TransactionId)>, @@ -343,9 +343,9 @@ impl Worterbuch { }) } - pub async fn pdelete_async(&self, key: Key) -> ConnectionResult { + pub async fn pdelete_async(&self, key: Key, quiet: bool) -> ConnectionResult { let (tx, rx) = oneshot::channel(); - let cmd = Command::PDeleteAsync(key, tx); + let cmd = Command::PDeleteAsync(key, quiet, tx); log::debug!("Queuing command {cmd:?}"); self.commands.send(cmd).await?; log::debug!("Command queued."); @@ -356,9 +356,10 @@ impl Worterbuch { pub async fn pdelete_generic( &self, key: Key, + quiet: bool, ) -> ConnectionResult<(KeyValuePairs, TransactionId)> { let (tx, rx) = oneshot::channel(); - let cmd = Command::PDelete(key, tx); + let cmd = Command::PDelete(key, quiet, tx); log::debug!("Queuing command {cmd:?}"); self.commands.send(cmd).await?; log::debug!("Command queued."); @@ -369,8 +370,9 @@ impl Worterbuch { pub async fn pdelete( &self, key: Key, + quiet: bool, ) -> ConnectionResult<(TypedKeyValuePairs, TransactionId)> { - let (kvps, tid) = self.pdelete_generic(key).await?; + let (kvps, tid) = self.pdelete_generic(key, quiet).await?; let typed_kvps = deserialize_key_value_pairs(kvps)?; Ok((typed_kvps, tid)) } @@ -1276,18 +1278,20 @@ async fn process_incoming_command( key, })) } - Command::PDelete(request_pattern, callback) => { + Command::PDelete(request_pattern, quiet, callback) => { callbacks.pdel.insert(transaction_id, callback); Some(CM::PDelete(PDelete { transaction_id, request_pattern, + quiet: Some(quiet), })) } - Command::PDeleteAsync(request_pattern, callback) => { + Command::PDeleteAsync(request_pattern, quiet, callback) => { callback.send(transaction_id).expect("error in callback"); Some(CM::PDelete(PDelete { transaction_id, request_pattern, + quiet: Some(quiet), })) } Command::Ls(parent, callback) => { diff --git a/worterbuch-common/schema/client.schema.yaml b/worterbuch-common/schema/client.schema.yaml index 6c86186..58fcdab 100644 --- a/worterbuch-common/schema/client.schema.yaml +++ b/worterbuch-common/schema/client.schema.yaml @@ -176,6 +176,9 @@ properties: requestPattern: description: The deletion pattern type: string + quiet: + description: If true, the server will not send the deleted values back to the client + type: boolean additionalProperties: false required: - transactionId diff --git a/worterbuch-common/src/client.rs b/worterbuch-common/src/client.rs index 7340309..89f6903 100644 --- a/worterbuch-common/src/client.rs +++ b/worterbuch-common/src/client.rs @@ -140,6 +140,7 @@ pub struct Delete { pub struct PDelete { pub transaction_id: TransactionId, pub request_pattern: RequestPattern, + pub quiet: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/worterbuch/src/server/common.rs b/worterbuch/src/server/common.rs index d006910..704912f 100644 --- a/worterbuch/src/server/common.rs +++ b/worterbuch/src/server/common.rs @@ -1060,7 +1060,11 @@ async fn pdelete( let response = PState { transaction_id: msg.transaction_id, request_pattern: msg.request_pattern, - event: PStateEvent::Deleted(deleted), + event: PStateEvent::Deleted(if msg.quiet.unwrap_or(false) { + vec![] + } else { + deleted + }), }; client