Git Product home page Git Product logo

redispool's Introduction

RedisPool

Library to Provide an Redis pool.

crates.io docs.rs Minimum Rust Version

License

This project is licensed under either Apache License, Version 2.0, zlib License, or MIT License, at your option.

Help

If you need help with this library or have suggestions please go to our Discord Group

Install

RedisPool uses tokio runtime.

# Cargo.toml
[dependencies]
redis_pool = "0.4.0"

Cargo Feature Flags

cluster: Enables Redis Cluster Client and connections.

Example

use redis_pool::{RedisPool, SingleRedisPool};
use axum::{Router, routing::get, extract::State};
use tokio::net::TcpListener;

#[tokio::main]
async fn main() {
    let redis_url = "redis://default:[email protected]:6379/0";
    let client = redis::Client::open(redis_url).expect("Error while testing the connection");
    let pool = RedisPool::from(client);

    // build our application with some routes
    let app = Router::new()
        .route("/test", get(test_pool))
        .with_state(pool);

    // run it
    let listener = TcpListener::bind("127.0.0.1:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

async fn test_pool(State(pool): State<SingleRedisPool>) -> String {
    let mut connection = pool.aquire().await.unwrap();
    let _: () = redis::pipe()
            .set(0, "Hello")
            .ignore()
            .query_async(&mut connection)
            .await
            .unwrap();

    redis::cmd("GET").arg(0).query_async(&mut connection).await.unwrap()
}

Running Tests

Docker must be installed because this library utilizes testcontainers to spin up redis intances. Additionally, the images contained in the docker directory need to be built and accessible in your local registry; this can be accomplished by running ./docker/build.sh.

redispool's People

Contributors

cking avatar genusistimelord avatar wilgaboury avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

wilgaboury cking

redispool's Issues

Performance Testing

The current testing just covers basic functionality, but it would be a good to add some tests that stress the pool with various combinations of parameters and measure the performance. Additionally, the current default pool size and connection limit were something I chose because they seemed reasonable, but it would better to find defaults based on empirical testing.

Sample code does not work.

This code gives me following error.

    let client =
        redis::Client::open(args.redis_address).expect("Error while testing the connection");
    let pool = RedisPool::from(client);
the trait bound `RedisPool<_, _>: From<redis::Client>` is not satisfied
the trait `From<redis::client::Client>` is implemented for `RedisPool<redis::client::Client, redis::aio::connection::Connection>`
for that trait implementation, expected `redis::client::Client`, found `redis::Client`

PubSub + Monitor Support

This library has it's own pool connection type that is a wrapper around an underlying ConnectionLike, that is only exposed as a reference. The into_pubsub and into into_monitor function for Connection require that ownership of the connection, so we likely need to make specialized pool connection implementations to accommodate these features.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.