Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
implement drop
Browse files Browse the repository at this point in the history
  • Loading branch information
xvello committed Nov 16, 2023
1 parent 1cc951e commit f9d2c26
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion capture-server/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl EphemeralRedis {
pub async fn new() -> Self {
Self {
client: redis::Client::open(DEFAULT_CONFIG.redis_url.clone())
.expect("failed to create Redis client"),
.expect("failed to create redis client"),
key_prefix: random_string("events_", 16),
}
}
Expand All @@ -271,3 +271,17 @@ impl ConfigMutator for EphemeralRedis {
config.redis_key_prefix = Some(self.key_prefix.clone())
}
}

impl Drop for EphemeralRedis {
fn drop(&mut self) {
let mut conn = self
.client
.get_connection()
.expect("failed to create redis conn");
let keys: Vec<String> = conn
.keys(format!("{}:::*", self.key_prefix))
.expect("failed to list keys");
debug!("deleting redis keys: {:?}", keys);
redis::Cmd::del(keys).execute(&mut conn);
}
}

0 comments on commit f9d2c26

Please sign in to comment.