Deadpool is a dead simple async pool for connections and objects of any type.
This crate implements a deadpool
manager for redis
.
| Feature | Description | Extra dependencies | Default |
| ------- | ----------- | ------------------ | ------- |
| config
| Enable support for config crate | config
, serde/derive
| yes |
| 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 |
```rust,ignore use deadpool_redis::redis::{cmd, Config, FromRedisValue};
async fn main() { let mut cfg = Config::default(); cfg.url = Some("redis://127.0.0.1/".tostring()); let pool = cfg.createpool().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()); } } ```
config
and dotenv
crate```rust use deadpool_redis::redis::{cmd, FromRedisValue}; use dotenv::dotenv; use serde::Deserialize;
struct Config { #[serde(default)] redis: deadpool_redis::Config }
impl Config {
pub fn fromenv() -> Result
async fn main() { dotenv().ok(); let cfg = Config::fromenv().unwrap(); let pool = cfg.redis.createpool().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()); } } ```
How can I enable features of the redis
crate?
Make sure that you depend on the same version of redis
as
deadpool-redis
does and enable the needed features in your own
Crate.toml
file:
toml
[dependencies]
deadpool-redis = { version = "0.8", features = ["config"] }
redis = { version = "0.20", default-features = false, features = ["tls"] }
Licensed under either of
at your option.