All Projects → importcjj → Mobc

importcjj / Mobc

Licence: other
A generic connection pool for Rust with async/await support

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Mobc

Polluter
The easiest solution to seed database with Go
Stars: ✭ 146 (+3.55%)
Mutual labels:  database, redis, postgres
Async Redis
First class async & promise support for redis.
Stars: ✭ 128 (-9.22%)
Mutual labels:  async, database, redis
Sqlx
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.
Stars: ✭ 5,039 (+3473.76%)
Mutual labels:  async, await, postgres
Groupco
PHP的服务化框架。适用于Api、Http Server、Rpc Server;帮助原生PHP项目转向微服务化。出色的性能与支持高并发的协程相结合
Stars: ✭ 473 (+235.46%)
Mutual labels:  pool, async, redis
Ship Hold
data access framework for Postgresql on nodejs
Stars: ✭ 110 (-21.99%)
Mutual labels:  database, postgres
Libpq.jl
A Julia wrapper for libpq
Stars: ✭ 109 (-22.7%)
Mutual labels:  database, postgres
Smproxy
Swoole MySQL Proxy 一个基于 MySQL 协议,Swoole 开发的MySQL数据库连接池。 A MySQL database connection pool based on MySQL protocol and Swoole.
Stars: ✭ 1,665 (+1080.85%)
Mutual labels:  pool, connection-pool
Tornadis
async minimal redis client for tornado ioloop designed for performances (use C hiredis parser)
Stars: ✭ 126 (-10.64%)
Mutual labels:  async, redis
Kangaroo
SQL client and admin tool for popular databases
Stars: ✭ 127 (-9.93%)
Mutual labels:  database, redis
Db Tutorial
💾 db-tutorial 是一个数据库教程。
Stars: ✭ 128 (-9.22%)
Mutual labels:  database, redis
Goose
A database migration tool. Supports SQL migrations and Go functions.
Stars: ✭ 2,112 (+1397.87%)
Mutual labels:  database, postgres
Tedis
redis client with typescript and esnext for nodejs
Stars: ✭ 109 (-22.7%)
Mutual labels:  async, redis
Micro
Asynchronous HTTP microservices
Stars: ✭ 9,987 (+6982.98%)
Mutual labels:  async, await
Pyproxy Async
基于 Python Asyncio + Redis 实现的代理池
Stars: ✭ 123 (-12.77%)
Mutual labels:  async, redis
Redis
Async Redis Client for PHP based on Amp.
Stars: ✭ 107 (-24.11%)
Mutual labels:  async, redis
Fastapi Plugins
FastAPI framework plugins
Stars: ✭ 104 (-26.24%)
Mutual labels:  async, redis
Postgres Operator
Production PostgreSQL for Kubernetes, from high availability Postgres clusters to full-scale database-as-a-service.
Stars: ✭ 2,166 (+1436.17%)
Mutual labels:  database, postgres
Ardb
A redis protocol compatible nosql, it support multiple storage engines as backend like Google's LevelDB, Facebook's RocksDB, OpenLDAP's LMDB, PerconaFT, WiredTiger, ForestDB.
Stars: ✭ 1,707 (+1110.64%)
Mutual labels:  database, redis
Reactive record
Generate ActiveRecord models for a pre-existing Postgres db
Stars: ✭ 132 (-6.38%)
Mutual labels:  database, postgres
Bojack
🐴 The unreliable key-value store
Stars: ✭ 101 (-28.37%)
Mutual labels:  database, redis

mobc

A generic connection pool with async/await support.

Inspired by r2d2 and Golang SQL package.

Documentation

Changelog

Note: mobc requires at least Rust 1.39.

Usage

[dependencies]
mobc = "0.7"

# For async-std runtime
# mobc = { version = "0.7", features = ["async-std"] }

Features

  • Support async/.await syntax
  • Support both tokio and async-std
  • High performance
  • Easy to customize
  • Dynamic configuration

Adaptors

Backend Adaptor Crate
tokio-postgres mobc-postgres
redis mobc-redis
arangodb mobc-arangors
lapin mobc-lapin

More DB adaptors are welcome.

Examples

More examples

Using an imaginary "foodb" database.

use mobc::{async_trait, Manager};

#[derive(Debug)]
pub struct FooError;

pub struct FooConnection;

impl FooConnection {
    pub async fn query(&self) -> String {
        "PONG".to_string()
    }
}

pub struct FooManager;

#[async_trait]
impl Manager for FooManager {
    type Connection = FooConnection;
    type Error = FooError;

    async fn connect(&self) -> Result<Self::Connection, Self::Error> {
        Ok(FooConnection)
    }

    async fn check(&self, conn: Self::Connection) -> Result<Self::Connection, Self::Error> {
        Ok(conn)
    }
}

Configures

max_open

Sets the maximum number of connections managed by the pool.

0 means unlimited, defaults to 10.

min_idle

Sets the maximum idle connection count maintained by the pool. The pool will maintain at most this many idle connections at all times, while respecting the value of max_open.

max_lifetime

Sets the maximum lifetime of connections in the pool. Expired connections may be closed lazily before reuse.

None meas reuse forever, defaults to None.

get_timeout

Sets the get timeout used by the pool. Calls to Pool::get will wait this long for a connection to become available before returning an error.

None meas never timeout, defaults to 30 seconds.

Variable

Some of the connection pool configurations can be adjusted dynamically. Each connection pool instance has the following methods:

  • set_max_open_conns
  • set_max_idle_conns
  • set_conn_max_lifetime

Stats

  • max_open - Maximum number of open connections to the database.
  • connections - The number of established connections both in use and idle.
  • in_use - The number of connections currently in use.
  • idle - The number of idle connections.
  • wait_count - The total number of connections waited for.
  • wait_duration - The total time blocked waiting for a new connection.
  • max_idle_closed - The total number of connections closed due to max_idle.
  • max_lifetime_closed - The total number of connections closed due to max_lifetime.

Compatibility

Because tokio is not compatible with other runtimes, such as async-std. So a database driver written with tokio cannot run in the async-std runtime. For example, you can't use redis-rs in tide because it uses tokio, so the connection pool which bases on redis-res can't be used in tide either.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].