2 releases
0.1.1 | May 8, 2023 |
---|---|
0.1.0 | Oct 18, 2022 |
#19 in #redis-cluster
1,248 downloads per month
6KB
bb8-redis-cluster
A Async redis cluster connection pool (bb8).
Example
#[tokio::main]
async fn main() {
let manager = RedisConnectionManager::new(vec!["redis://localhost:1234"]).unwrap();
let pool = bb8::Pool::builder()
.max_size(15)
.build(manager)
.await
.unwrap();
for _ in 0..20 {
let pool = pool.clone();
tokio::spawn(async move {
let mut conn = pool.get().await.unwrap();
let reply: String = cmd("PING").query_async(&mut *conn).await.unwrap();
assert_eq!("PONG", reply);
});
}
}
lib.rs
:
Redis Cluster support for the bb8
connection pool.
Example
use futures_util::future::join_all;
use bb8_redis_cluster::{
bb8,
redis_cluster_async::redis::{cmd, AsyncCommands},
RedisConnectionManager
};
#[tokio::main]
async fn main() {
let manager = RedisConnectionManager::new(vec!["redis://localhost"]).unwrap();
let pool = 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 reply: String = cmd("PING").query_async(&mut *conn).await.unwrap();
assert_eq!("PONG", reply);
}));
}
join_all(handles).await;
}
Dependencies
~8–18MB
~228K SLoC