#redis #async #database #pool

ciseaux_client

Just a Redis Pool implementation

6 releases

0.3.1 May 21, 2020
0.3.0 Mar 14, 2020
0.2.1 Feb 17, 2020
0.1.1 Feb 14, 2020

#73 in #redis

MIT license

14KB
251 lines

ciseaux_client

Rust 1.39 and tokio required !

Just an asynchronous Redis Pool implementation I did for personnal use, not sure if it is reliable and safe to use (There is no unsafe here, but the pool management is really basic).

This crate is (probably) NOT PRODUCTION READY, I have no experience, if you want to use it in personnal or professional projet, please check the code first.


lib.rs:

This is a simple asynchronous Redis Pool, currently only supports a connection pool to a Single Redis instance, and will probably provide Cluster support later. If you want to understand how to use it, see examples and/or CiseauxSingle struct.

The library currently supports tokio only (Because of redis-rs, async-std support is coming), and require at least Rust 1.39

[dependencies]
ciseaux_client = "0.3"

Example

Create a connection pool default settings and the provided redis::Client (from redis-rs)

use redis::{Client, Cmd};
use ciseaux_client::CiseauxSingle;

#[tokio::main]
async fn main() {
    let redis_client = Client::open("redis://127.0.0.1:6379").unwrap();
    let db_pool = CiseauxSingle::new(redis_client).await.expect("Failed to create Pool");
    // You can safely share CiseauxSingle between threads
    // since it use Arcs and Mutexes under the hood)
    let res = match db_pool.query::<_, Option<String>>(&redis::Cmd::get("hello")).await {
        Ok(v) => v,
        Err(e) => return,// Handle Error
    };
    let hello = match res {
        Some(v) => v,
        None => return,// Handle Nil value
    };
    println!("{}", hello);
}

Dependencies

~6MB
~136K SLoC