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 |
```rust,ignore use deadpoolredis::{cmd, Config}; use deadpoolredis::redis::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"]) .executeasync(&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 deadpoolredis::cmd; use deadpoolredis::redis::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"]) .executeasync(&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.6", features = ["config"] }
redis = { version = "0.17", default-features = false, features = ["tls"] }
Licensed under either of
at your option.