Skip to content

Commit

Permalink
Fix kv purge with prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Pietrek <[email protected]>
  • Loading branch information
Jarema committed Jul 24, 2023
1 parent 625d1da commit 24fb246
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion async-nats/src/jetstream/kv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,13 @@ impl Store {
return Err(PurgeError::new(PurgeErrorKind::InvalidKey));
}

let subject = format!("{}{}", self.prefix.as_str(), key.as_ref());
let mut subject = String::new();
if self.use_jetstream_prefix {
subject.push_str(&self.stream.context.prefix);
subject.push('.');
}
subject.push_str(self.put_prefix.as_ref().unwrap_or(&self.prefix));
subject.push_str(key.as_ref());

let mut headers = crate::HeaderMap::default();
headers.insert(KV_OPERATION, HeaderValue::from(KV_OPERATION_PURGE));
Expand Down
4 changes: 4 additions & 0 deletions async-nats/tests/kv_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,10 @@ mod kv {
let name = test.get("name").await.unwrap();
assert_eq!(from_utf8(&name.unwrap()).unwrap(), "ivan".to_string());

test.purge("name").await.unwrap();
let name = test.get("name").await.unwrap();
assert!(name.is_none());

// Shutdown HUB and test get still work.
drop(hub_server);

Expand Down

0 comments on commit 24fb246

Please sign in to comment.