Deadpool for Redis Latest Version Unsafe forbidden Rust 1.63+

Deadpool is a dead simple async pool for connections and objects of any type.

This crate implements a deadpool manager for redis.

Features

| Feature | Description | Extra dependencies | Default | | ---------------- | --------------------------------------------------------------------- | ------------------------------------------------- | ------- | | rt_tokio_1 | Enable support for tokio crate | deadpool/rt_tokio_1, redis/tokio-comp | yes | | rt_async-std_1 | Enable support for async-std crate | deadpool/rt_async-std_1, redis/async-std-comp | no | | serde | Enable support for serde crate | deadpool/serde, serde/derive | no |

Example

```rust use std::env;

use deadpool_redis::{redis::{cmd, FromRedisValue}, Config, Runtime};

[tokio::main]

async fn main() { let mut cfg = Config::fromurl(env::var("REDISURL").unwrap()); let pool = cfg.createpool(Some(Runtime::Tokio1)).unwrap(); { let mut conn = pool.get().await.unwrap(); cmd("SET") .arg(&["deadpool/testkey", "42"]) .queryasync::<_, ()>(&mut conn) .await.unwrap(); } { let mut conn = pool.get().await.unwrap(); let value: String = cmd("GET") .arg(&["deadpool/testkey"]) .queryasync(&mut conn) .await.unwrap(); asserteq!(value, "42".tostring()); } } ```

Example with config and dotenv crate

```rust use deadpool_redis::{redis::{cmd, FromRedisValue}, Runtime}; use dotenv::dotenv;

use serde_1 as serde;

[derive(Debug, serde::Deserialize)]

#[serde(crate = "serde_1")]

struct Config { #[serde(default)] redis: deadpool_redis::Config }

impl Config { pub fn fromenv() -> Result { config::Config::builder() .addsource(config::Environment::default().separator("_")) .build()? .trydeserialize() } }

[tokio::main]

async fn main() { dotenv().ok(); let cfg = Config::fromenv().unwrap(); let pool = cfg.redis.createpool(Some(Runtime::Tokio1)).unwrap(); { let mut conn = pool.get().await.unwrap(); cmd("SET") .arg(&["deadpool/testkey", "42"]) .queryasync::<_, ()>(&mut conn) .await.unwrap(); } { let mut conn = pool.get().await.unwrap(); let value: String = cmd("GET") .arg(&["deadpool/testkey"]) .queryasync(&mut conn) .await.unwrap(); asserteq!(value, "42".tostring()); } } ```

FAQ

License

Licensed under either of

at your option.