mobc_redis_cluster/
lib.rs1use mobc::async_trait;
2use mobc::Manager;
3pub use redis;
4
5pub use redis_cluster_async::{Client,Connection};
6
7pub struct RedisClusterConnectionManager {
8 client: Client,
9}
10
11impl RedisClusterConnectionManager {
12 pub fn new(c: Client) -> Self {
13 Self { client: c }
14 }
15}
16
17#[async_trait]
18impl Manager for RedisClusterConnectionManager {
19 type Connection = Connection;
20 type Error = redis::RedisError;
21
22 async fn connect(&self) -> Result<Self::Connection, Self::Error> {
23 let c = self.client.get_connection().await?;
24 Ok(c)
25 }
26
27 async fn check(&self, mut conn: Self::Connection) -> Result<Self::Connection, Self::Error> {
28 redis::cmd("PING").query_async(&mut conn).await?;
29 Ok(conn)
30 }
31}
32