2 releases

0.0.0-alpha2 Dec 4, 2024

#407 in Asynchronous

Download history 232/week @ 2024-12-02

232 downloads per month

MIT license

4KB

bb8-valkey

A connection pool for tokio-valkey.

It is still a work-in-progress.

Usage

use bb8::Pool;
use bb8_valkey::ValkeyConnectionManager;
use futures_util::future::join_all;
use std::net::{Ipv6Addr, SocketAddr};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let addr = SocketAddr::from((Ipv6Addr::LOCALHOST, 6379));
    let manager = ValkeyConnectionManager::new(addr).await?;
    let pool = Pool::builder().build(manager).await?;

    let mut handles = Vec::with_capacity(10);
    for _i in 0..10 {
        let pool = pool.clone();
        handles.push(tokio::spawn(async move {
            let mut conn = pool.get().await.unwrap();
        
            // this is not implemented yet
            let reply: String = cmd("PING").query_async(&mut *conn).await.unwrap();
            assert_eq!("PONG", reply);
        }));
    }
    join_all(handles).await;
    Ok(())
}

Dependencies

~4–12MB
~136K SLoC