前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Rust项目推荐】异步连接池mobc更新, 支持tokio0.2和async-std,欢迎使用

【Rust项目推荐】异步连接池mobc更新, 支持tokio0.2和async-std,欢迎使用

作者头像
MikeLoveRust
发布2019-12-25 17:14:53
1.6K0
发布2019-12-25 17:14:53
举报

github

0.3版本支持tokio0.2,如果你在使用tokio0.2-alpha.6 请使用0.2版本

mobc

A generic connection pool, but async/.await

Documentation

Note: mobc requires at least Rust 1.39.

Features

  • Support async/.await syntax.
  • Support tokio 0.2 and async-std 1.0 runtimes.
  • Simple and fast customization

Adapter

  • mobc-redis = "0.3.1"
  • mobc-postgres = "0.3.1"

Usage

If you are using tokio 0.2-alpha.6, use mobc 0.2.11.

代码语言:javascript
复制
[dependencies]
mobc = "0.3"
foo demo
代码语言:javascript
复制
use tokio;

#[tokio::main]
async fn main() {
    let manager = mobc_foodb::FooConnectionManager::new("localhost:1234");
    let pool = mobc::Pool::builder()
        .max_size(15)
        .build(manager)
        .await
        .unwrap();

    for _ in 0..20 {
        let pool = pool.clone();
        tokio::spawn(async {
            let conn = pool.get().await.unwrap();
            // use the connection
            // it will be returned to the pool when it falls out of scope.
        });
    }
}

阅读原文:https://rust-china.org/article?id=6ce763ff-2c8a-44df-8053-3d7961806a5f

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2019-12-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Rust语言学习交流 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • mobc
    • Features
      • Adapter
        • Usage
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档