MCPcopy Index your code
hub / github.com/djc/bb8

github.com/djc/bb8 @bb8-redis-0.26.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release bb8-redis-0.26.0 ↗ · + Follow
175 symbols 551 edges 10 files 24 documented · 14% updated 8d agobb8-redis-0.26.0 · 2025-12-09★ 94820 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

bb8

Documentation Crates.io Build status codecov Chat License: MIT

A full-featured connection pool, designed for asynchronous connections (using tokio). Originally based on r2d2.

Opening a new database connection every time one is needed is both inefficient and can lead to resource exhaustion under high traffic conditions. A connection pool maintains a set of open connections to a database, handing them out for repeated use.

bb8 is agnostic to the connection type it is managing. Implementors of the ManageConnection trait provide the database-specific logic to create and check the health of connections.

A (possibly not exhaustive) list of adapters for different backends:

Backend Adapter Crate
tokio-postgres bb8-postgres (in-tree)
redis bb8-redis (in-tree)
redis_cluster_async bb8-redis-cluster
rsmq rsmq_async
bolt-client bb8-bolt
diesel diesel_async
tiberius bb8-tiberius
nebula-client bb8-nebula
memcache-async bb8-memcached
lapin bb8-lapin
arangors bb8-arangodb
tonic bb8-tonic

Example

Using an imaginary "foodb" database.

#[tokio::main]
async fn main() {
    let manager = bb8_foodb::FooConnectionManager::new("localhost:1234");
    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 conn = pool.get().await.unwrap();
            // use the connection
            // it will be returned to the pool when it falls out of scope.
        });
    }
}

License

Licensed under the MIT license (LICENSE).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be licensed as above, without any additional terms or conditions.

Extension points exported contracts — how you extend this code

ManageConnection (Interface)
A trait which provides connection-specific functionality. [11 implementers]
bb8/src/api.rs
CustomizeConnection (Interface)
A trait which provides functionality to initialize a connection [2 implementers]
bb8/src/api.rs
ErrorSink (Interface)
A trait to receive errors generated by connection management that aren't tied to any particular caller. [1 implementers]
bb8/src/api.rs

Core symbols most depended-on inside this repo

get
called by 42
bb8/src/api.rs
build
called by 26
bb8/src/api.rs
clone
called by 21
bb8/src/api.rs
max_size
called by 21
bb8/src/api.rs
lock
called by 12
bb8/src/lib.rs
connection_timeout
called by 12
bb8/src/api.rs
min_idle
called by 11
bb8/src/api.rs
len
called by 5
bb8/src/internals.rs

Shape

Method 101
Class 32
Function 32
Enum 7
Interface 3

Languages

Rust100%

Modules by API surface

bb8/src/api.rs50 symbols
bb8/tests/test.rs46 symbols
bb8/src/internals.rs33 symbols
bb8/src/inner.rs18 symbols
postgres/examples/custom_state.rs11 symbols
postgres/src/lib.rs7 symbols
redis/src/lib.rs5 symbols
bb8/src/lib.rs3 symbols
postgres/examples/txn.rs1 symbols
postgres/examples/static_select.rs1 symbols

For agents

$ claude mcp add bb8 \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact