ping redis
This commit is contained in:
parent
1c6e9dd01d
commit
3db009977a
2 changed files with 32 additions and 0 deletions
|
@ -110,6 +110,11 @@ impl MCaptchaRedisConnection {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ping redis
|
||||||
|
pub async fn ping(&self) -> bool {
|
||||||
|
self.0.ping().await
|
||||||
|
}
|
||||||
|
|
||||||
/// Add visitor
|
/// Add visitor
|
||||||
pub async fn add_visitor(&self, msg: AddVisitor) -> CaptchaResult<Option<AddVisitorResult>> {
|
pub async fn add_visitor(&self, msg: AddVisitor) -> CaptchaResult<Option<AddVisitorResult>> {
|
||||||
let res: String = self.0.exec(redis::cmd(ADD_VISITOR).arg(&[msg.0])).await?;
|
let res: String = self.0.exec(redis::cmd(ADD_VISITOR).arg(&[msg.0])).await?;
|
||||||
|
@ -328,6 +333,8 @@ pub mod tests {
|
||||||
r.add_token(&add_challenge_msg).await.unwrap();
|
r.add_token(&add_challenge_msg).await.unwrap();
|
||||||
assert!(r.delete_token(&challenge_msg).await.is_ok());
|
assert!(r.delete_token(&challenge_msg).await.is_ok());
|
||||||
|
|
||||||
|
assert!(r.ping().await);
|
||||||
|
|
||||||
assert!(r.delete_captcha(CAPTCHA_NAME).await.is_ok());
|
assert!(r.delete_captcha(CAPTCHA_NAME).await.is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,18 @@ impl RedisConnection {
|
||||||
RedisConnection::Cluster(con) => cmd.query(&mut *con.borrow_mut()),
|
RedisConnection::Cluster(con) => cmd.query(&mut *con.borrow_mut()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn ping(&self) -> bool {
|
||||||
|
if let Ok(redis::Value::Status(v)) = self.exec(&mut redis::cmd("PING")).await {
|
||||||
|
if v == "PONG" {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -126,3 +138,16 @@ impl Redis {
|
||||||
(redis, client)
|
(redis, client)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[actix_rt::test]
|
||||||
|
async fn ping_works() {
|
||||||
|
let r = Redis::new(RedisConfig::Single("redis://127.0.0.1".into()))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert!(r.get_client().ping().await);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue