[][src]Crate bb8_redis

Redis support for the bb8 connection pool.

Example

use futures::future::join_all;
use bb8_redis::{
    bb8,
    redis::{cmd, AsyncCommands},
    RedisConnectionManager, RedisPool
};

#[tokio::main]
async fn main() {
    let manager = RedisConnectionManager::new("redis://localhost").unwrap();
    let pool = RedisPool::new(bb8::Pool::builder().build(manager).await.unwrap());

    let mut handles = vec![];

    for _i in 0..10 {
        let pool = pool.clone();

        handles.push(tokio::spawn(async move {
            let mut conn = pool.get().await.unwrap();
            let conn = conn.as_mut().unwrap();

            let reply: String = cmd("PING").query_async(conn).await.unwrap();

            assert_eq!("PONG", reply);
        }));
    }

    join_all(handles).await;
}

Re-exports

pub use bb8;
pub use redis;

Structs

RedisConnectionManager

A bb8::ManageConnection for redis::Client::get_async_connection.

RedisPool

RedisPool is a convenience wrapper around bb8::Pool that hides the fact that RedisConnectionManager uses an Option<Connection> to smooth over the API incompatibility.