Crate deadpool_redis[−][src]
Expand description
Deadpool for Redis
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 |
---|---|---|---|
config | Enable support for config crate | config , serde/derive | yes |
Example
use deadpool_redis::{cmd, Config}; use deadpool_redis::redis::FromRedisValue; #[tokio::main] async fn main() { let mut cfg = Config::default(); cfg.url = Some("redis://127.0.0.1/".to_string()); let pool = cfg.create_pool().unwrap(); { let mut conn = pool.get().await.unwrap(); cmd("SET") .arg(&["deadpool/test_key", "42"]) .execute_async(&mut conn) .await.unwrap(); } { let mut conn = pool.get().await.unwrap(); let value: String = cmd("GET") .arg(&["deadpool/test_key"]) .query_async(&mut conn) .await.unwrap(); assert_eq!(value, "42".to_string()); } }
Example with config
and dotenv
crate
use deadpool_redis::cmd; use deadpool_redis::redis::FromRedisValue; use dotenv::dotenv; use serde::Deserialize; #[derive(Debug, Deserialize)] struct Config { #[serde(default)] redis: deadpool_redis::Config } impl Config { pub fn from_env() -> Result<Self, ::config_crate::ConfigError> { let mut cfg = ::config_crate::Config::new(); cfg.merge(::config_crate::Environment::new().separator("__"))?; cfg.try_into() } } #[tokio::main] async fn main() { dotenv().ok(); let cfg = Config::from_env().unwrap(); let pool = cfg.redis.create_pool().unwrap(); { let mut conn = pool.get().await.unwrap(); cmd("SET") .arg(&["deadpool/test_key", "42"]) .execute_async(&mut conn) .await.unwrap(); } { let mut conn = pool.get().await.unwrap(); let value: String = cmd("GET") .arg(&["deadpool/test_key"]) .query_async(&mut conn) .await.unwrap(); assert_eq!(value, "42".to_string()); } }
FAQ
-
How can I enable features of the
redis
crate?Make sure that you depend on the same version of
redis
asdeadpool-redis
does and enable the needed features in your ownCrate.toml
file:[dependencies] deadpool-redis = { version = "0.7.1", features = ["config"] } redis = { version = "0.20", default-features = false, features = ["tls"] }
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Re-exports
pub use redis; |
Structs
Cmd | Wrapper for |
Config | Configuration object. By enabling the |
ConnectionWrapper | A wrapper for |
Manager | The manager for creating and recyling lapin connections |
Pipeline | Wrapper for |
PoolConfig | Re-export deadpool::managed::PoolConfig |
Functions
cmd | Shortcut function to creating a command with a single argument. |
pipe | Shortcut for creating a new pipeline. |
Type Definitions
Connection | A type alias for using |
Pool | A type alias for using |
PoolError | A type alias for using |