Skip to content

Commit

Permalink
Merge deadpool-redis-cluster into deadpool-redis.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Nov 28, 2023
1 parent b5a11ad commit 9f18b6c
Show file tree
Hide file tree
Showing 12 changed files with 134 additions and 211 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ Backend | Crate | Latest Version |
[tokio-postgres](https://crates.io/crates/tokio-postgres) | [deadpool-postgres](https://crates.io/crates/deadpool-postgres) | [![Latest Version](https://img.shields.io/crates/v/deadpool-postgres.svg)](https://crates.io/crates/deadpool-postgres) |
[lapin](https://crates.io/crates/lapin) (AMQP) | [deadpool-lapin](https://crates.io/crates/deadpool-lapin) | [![Latest Version](https://img.shields.io/crates/v/deadpool-lapin.svg)](https://crates.io/crates/deadpool-lapin) |
[redis](https://crates.io/crates/redis) | [deadpool-redis](https://crates.io/crates/deadpool-redis) | [![Latest Version](https://img.shields.io/crates/v/deadpool-redis.svg)](https://crates.io/crates/deadpool-redis) |
[redis_cluster_async](https://crates.io/crates/redis_cluster_async) | [deadpool-redis-cluster](https://crates.io/crates/deadpool-redis-cluster) | [![Latest Version](https://img.shields.io/crates/v/deadpool-redis.svg)](https://crates.io/crates/deadpool-redis-cluster) |
[async-memcached](https://crates.io/crates/async-memcached) | [deadpool-memcached](https://crates.io/crates/deadpool-memcached) | [![Latest Version](https://img.shields.io/crates/v/deadpool-memcached.svg)](https://crates.io/crates/deadpool-memcached) |
[rusqlite](https://crates.io/crates/rusqlite) | [deadpool-sqlite](https://crates.io/crates/deadpool-sqlite) | [![Latest Version](https://img.shields.io/crates/v/deadpool-sqlite.svg)](https://crates.io/crates/deadpool-sqlite) |
[diesel](https://crates.io/crates/diesel) | [deadpool-diesel](https://crates.io/crates/deadpool-diesel) | [![Latest Version](https://img.shields.io/crates/v/deadpool-diesel.svg)](https://crates.io/crates/deadpool-diesel) |
Expand Down
5 changes: 0 additions & 5 deletions redis-cluster/CHANGELOG.md

This file was deleted.

42 changes: 0 additions & 42 deletions redis-cluster/Cargo.toml

This file was deleted.

122 changes: 0 additions & 122 deletions redis-cluster/README.md

This file was deleted.

5 changes: 5 additions & 0 deletions redis/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## v0.14.0

* Merge `deadpool-redis-cluster` into `deadpool-redis`.
* Remove `redis_cluster_async` dependency in favor of `redis::cluster` / `redis::cluster_async`.

## v0.13.0

* Update `deadpool` dependency to version `0.10`
Expand Down
6 changes: 5 additions & 1 deletion redis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ version = "0.13.0"
edition = "2018"
resolver = "2"
rust-version = "1.63"
authors = ["Michael P. Jung <[email protected]>"]
authors = [
"Michael P. Jung <[email protected]>",
"Subeom Choi <[email protected]>",
]
description = "Dead simple async pool for redis"
keywords = ["async", "redis", "pool"]
license = "MIT OR Apache-2.0"
Expand All @@ -20,6 +23,7 @@ default = ["rt_tokio_1"]
rt_tokio_1 = ["deadpool/rt_tokio_1", "redis/tokio-comp"]
rt_async-std_1 = ["deadpool/rt_async-std_1", "redis/async-std-comp"]
serde = ["deadpool/serde", "serde_1"]
cluster = ["redis/cluster-async"]

[dependencies]
deadpool = { path = "../", version = "0.10.0", default-features = false, features = [
Expand Down
89 changes: 88 additions & 1 deletion redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ manager for [`redis`](https://crates.io/crates/redis).
| `rt_tokio_1` | Enable support for [tokio](https://crates.io/crates/tokio) crate | `deadpool/rt_tokio_1`, `redis/tokio-comp` | yes |
| `rt_async-std_1` | Enable support for [async-std](https://crates.io/crates/config) crate | `deadpool/rt_async-std_1`, `redis/async-std-comp` | no |
| `serde` | Enable support for [serde](https://crates.io/crates/serde) crate | `deadpool/serde`, `serde/derive` | no |
| `cluster` | Enable support for Redis Cluster | `redis/cluster-async` | no |

## Example

Expand Down Expand Up @@ -43,7 +44,7 @@ async fn main() {
}
```

## Example with `config` and `dotenv` crate
### Example with `config` and `dotenv` crate

```rust
use deadpool_redis::{redis::{cmd, FromRedisValue}, Runtime};
Expand Down Expand Up @@ -89,6 +90,92 @@ async fn main() {
}
```

## Example (Cluster)

```rust
use std::env;
use deadpool_redis::{redis::{cmd, FromRedisValue}};
use deadpool_redis::cluster::{Config, Runtime};

#[tokio::main]
async fn main() {
let redis_urls = env::var("REDIS_CLUSTER__URLS")
.unwrap()
.split(',')
.map(String::from)
.collect::<Vec<_>>();
let mut cfg = Config::from_urls(redis_urls);
let pool = cfg.create_pool(Some(Runtime::Tokio1)).unwrap();
{
let mut conn = pool.get().await.unwrap();
cmd("SET")
.arg(&["deadpool/test_key", "42"])
.query_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

```rust
use deadpool_redis::redis::{cmd, FromRedisValue},
use deadpool_redis::cluster::{Runtime};
use dotenv::dotenv;
# use serde_1 as serde;

#[derive(Debug, serde::Deserialize)]
# #[serde(crate = "serde_1")]
struct Config {
#[serde(default)]
redis_cluster: deadpool_redis::cluster::Config
}

impl Config {
pub fn from_env() -> Result<Self, config::ConfigError> {
config::Config::builder()
.add_source(
config::Environment::default()
.separator("__")
.try_parsing(true)
.list_separator(","),
)
.build()?
.try_deserialize()
}
}

#[tokio::main]
async fn main() {
dotenv().ok();
let cfg = Config::from_env().unwrap();
let pool = cfg.redis_cluster.create_pool(Some(Runtime::Tokio1)).unwrap();
{
let mut conn = pool.get().await.unwrap();
cmd("SET")
.arg(&["deadpool/test_key", "42"])
.query_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?**
Expand Down
8 changes: 4 additions & 4 deletions redis-cluster/src/config.rs → redis/src/cluster/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use redis::RedisError;
#[cfg(feature = "serde")]
use serde_1::{Deserialize, Serialize};

use crate::{CreatePoolError, Pool, PoolBuilder, PoolConfig, RedisResult, Runtime};
use super::{CreatePoolError, Pool, PoolBuilder, PoolConfig, RedisResult, Runtime};

/// Configuration object.
///
Expand Down Expand Up @@ -79,10 +79,10 @@ impl Config {
pub fn builder(&self) -> Result<PoolBuilder, ConfigError> {
let manager = match (&self.urls, &self.connections) {
(Some(urls), None) => {
crate::Manager::new(urls.iter().map(|url| url.as_str()).collect())?
super::Manager::new(urls.iter().map(|url| url.as_str()).collect())?
}
(None, Some(connections)) => crate::Manager::new(connections.clone())?,
(None, None) => crate::Manager::new(vec![ConnectionInfo::default()])?,
(None, Some(connections)) => super::Manager::new(connections.clone())?,
(None, None) => super::Manager::new(vec![ConnectionInfo::default()])?,
(Some(_), Some(_)) => return Err(ConfigError::UrlAndConnectionSpecified),
};
let pool_config = self.get_pool_config();
Expand Down
Loading

0 comments on commit 9f18b6c

Please sign in to comment.