Skip to content

Commit

Permalink
new: added timeout support for redis plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
evilsocket committed Oct 30, 2023
1 parent 5c8da59 commit 6bc3e28
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/plugins/redis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ impl Plugin for Redis {
Ok(())
}

async fn attempt(
&self,
creds: &Credentials,
_timeout: Duration,
) -> Result<Option<Loot>, Error> {
async fn attempt(&self, creds: &Credentials, timeout: Duration) -> Result<Option<Loot>, Error> {
let url = format!(
"{}://{}:{}@{}:{}",
if self.ssl { "rediss" } else { "redis" },
Expand All @@ -60,9 +56,10 @@ impl Plugin for Redis {
);

let client = redis::Client::open(url).map_err(|e| e.to_string())?;
let mut conn = client
.get_async_connection() // there is no get_async_connection_with_timeout() method

let mut conn = tokio::time::timeout(timeout, client.get_async_connection())
.await
.map_err(|e| e.to_string())?
.map_err(|e| e.to_string())?;

redis::cmd("PING")
Expand Down

0 comments on commit 6bc3e28

Please sign in to comment.