From f9d2c260b448bc6010db115cfb1972d6a2384cf3 Mon Sep 17 00:00:00 2001 From: Xavier Vello Date: Thu, 16 Nov 2023 17:24:59 +0100 Subject: [PATCH] implement drop --- capture-server/tests/common.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/capture-server/tests/common.rs b/capture-server/tests/common.rs index 94fe762..93c24af 100644 --- a/capture-server/tests/common.rs +++ b/capture-server/tests/common.rs @@ -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), } } @@ -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 = conn + .keys(format!("{}:::*", self.key_prefix)) + .expect("failed to list keys"); + debug!("deleting redis keys: {:?}", keys); + redis::Cmd::del(keys).execute(&mut conn); + } +}