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.

```toml

Cargo.toml

[dependencies] redis_pool = "0.1" ```

Cargo Feature Flags

cluster: Enables Redis Cluster Client and connections.

Example

```rust norun use redispool::{RedisPool, SingleRedisPool}; use axum::{Router, routing::get, extract::State}; use std::net::SocketAddr;

[tokio::main]

async fn main() { let redisurl = "redis://default:YourSecretPassWord@127.0.0.1:6379/0"; let client = redis::Client::open(redisurl).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 addr = SocketAddr::from(([127, 0, 0, 1], 3000));
tracing::debug!("listening on {}", addr);
axum::Server::bind(&addr)
    .serve(app.into_make_service())
    .await
    .unwrap();

}

async fn testpool(State(pool): State) -> String { let mut connection = pool.aquire().await.unwrap(); let _: () = redis::pipe() .set(0, "Hello") .ignore() .queryasync(&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.