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 |
| ------- | ----------- | ------------------ | ------- |
| 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 |
```rust use deadpool_redis::{redis::{cmd, FromRedisValue}, Config, Runtime};
async fn main() { let mut cfg = Config::fromurl("redis://127.0.0.1/"); 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()); } } ```
config
and dotenv
crate```rust use deadpool_redis::{redis::{cmd, FromRedisValue}, Runtime}; use dotenv::dotenv;
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(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()); } } ```
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.9", features = ["serde"] }
redis = { version = "0.21", default-features = false, features = ["tls"] }
Licensed under either of
at your option.