Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #65

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "redis-async"
version = "0.8.1"
version = "0.9.0"
authors = ["Ben Ashford <[email protected]>"]
license = "MIT/Apache-2.0"
readme = "README.md"
Expand All @@ -10,30 +10,35 @@ keywords = ["redis", "tokio"]
edition = "2018"

[dependencies]
async-global-executor = { version = "1.4", optional = true }
async-net = { version = "1.5", optional = true }
bytes_05 = { package = "bytes", version = "0.5", optional = true }
bytes_06 = { package = "bytes", version = "^0.6.0", optional = true }
bytes_10 = { package = "bytes", version = "1.0", optional = true }
log = "^0.4.11"
lwactors = "0.2"
futures-channel = "^0.3.7"
futures-sink = "^0.3.7"
futures-util = "^0.3.7"
futures-util = { version = "^0.3.7", features = ["sink"] }
thiserror = "1.0"
tokio_02 = { package = "tokio", version = "0.2", features = ["rt-core", "net", "time"], optional = true}
tokio_03 = { package = "tokio", version = "^0.3.2", features = ["rt", "net", "time"], optional = true }
tokio_10 = { package = "tokio", version = "1.0", features = ["rt", "net", "time"], optional = true }
tokio-util_03 = { package = "tokio-util", version = "0.3", features = ["codec"], optional = true }
tokio-util_05 = { package = "tokio-util", version = "^0.5", features = ["codec"], optional = true }
tokio-util_06 = { package = "tokio-util", version = "0.6", features = ["codec"], optional = true }

[dev-dependencies]
env_logger = "^0.8.1"
futures = "^0.3.7"
async-std = { version = "1.8", features = ["attributes"] }
tokio_02 = { package = "tokio", version = "0.2", features = ["full"] }
tokio_03 = { package = "tokio", version = "^0.3.2", features = ["full"] }
tokio_10 = { package = "tokio", version = "1.0", features = ["full"] }

[features]
default = ["tokio03"]
default = ["tokio10"]

tokio02 = ["bytes_05", "tokio_02", "tokio-util_03"]
tokio03 = ["bytes_06", "tokio_03", "tokio-util_05"]
tokio10 = ["bytes_10", "tokio_10", "tokio-util_06"]
async-std18 = ["bytes_10", "async-net", "async-global-executor", "with_async_std"]
tokio02 = ["bytes_05", "tokio_02", "tokio-util_03", "tokio_codec", "lwactors/with_tokio02", "with_tokio"]
tokio10 = ["bytes_10", "tokio_10", "tokio-util_06", "tokio_codec", "lwactors/with_tokio10", "with_tokio"]

tokio_codec = []
with_async_std = ["lwactors/with_async_global_executor14"]
with_tokio = ["lwactors/tokio10"]
14 changes: 11 additions & 3 deletions examples/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#[cfg(feature = "tokio02")]
extern crate tokio_02 as tokio;

#[cfg(feature = "tokio03")]
extern crate tokio_03 as tokio;

#[cfg(feature = "tokio10")]
extern crate tokio_10 as tokio;

Expand All @@ -23,8 +20,19 @@ use futures::{sink::SinkExt, stream::StreamExt};

use redis_async::{client, resp_array};

#[cfg(feature = "with_tokio")]
#[tokio::main]
async fn main() {
do_main().await;
}

#[cfg(feature = "with_async_std")]
#[async_std::main]
async fn main() {
do_main().await;
}

async fn do_main() {
let addr = env::args()
.nth(1)
.unwrap_or_else(|| "127.0.0.1:6379".to_string())
Expand Down
28 changes: 19 additions & 9 deletions examples/psubscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,41 @@
#[cfg(feature = "tokio02")]
extern crate tokio_02 as tokio;

#[cfg(feature = "tokio03")]
extern crate tokio_03 as tokio;

#[cfg(feature = "tokio10")]
extern crate tokio_10 as tokio;

use std::env;

use futures::StreamExt;

use redis_async::{client, resp::FromResp};
use redis_async::{client::ConnectionBuilder, protocol::FromResp};

#[cfg(feature = "with_tokio")]
#[tokio::main]
async fn main() {
do_main().await;
}

#[cfg(feature = "with_async_std")]
#[async_std::main]
async fn main() {
do_main().await;
}

async fn do_main() {
env_logger::init();
let topic = env::args().nth(1).unwrap_or_else(|| "test.*".to_string());

let addr = env::args()
.nth(2)
.unwrap_or_else(|| "127.0.0.1:6379".to_string())
.parse()
.unwrap();
.unwrap_or_else(|| "127.0.0.1:6379".to_string());

let pubsub_con = client::pubsub_connect(addr)
let pubsub_con = ConnectionBuilder::new(addr)
.expect("Cannot parse address")
.pubsub_connect()
.await
.expect("Cannot connect to Redis");
.expect("Cannot open connection");

let mut msgs = pubsub_con
.psubscribe(&topic)
.await
Expand Down
29 changes: 19 additions & 10 deletions examples/realistic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#[cfg(feature = "tokio02")]
extern crate tokio_02 as tokio;

#[cfg(feature = "tokio03")]
extern crate tokio_03 as tokio;

#[cfg(feature = "tokio10")]
extern crate tokio_10 as tokio;

Expand All @@ -23,30 +20,42 @@ use futures_util::future;

// use futures::{future, Future};

use redis_async::{client, resp_array};
use redis_async::{client::ConnectionBuilder, resp_array};

/// An artificial "realistic" non-trivial example to demonstrate usage
#[cfg(feature = "with_tokio")]
#[tokio::main]
async fn main() {
do_main().await;
}

#[cfg(feature = "with_async_std")]
#[async_std::main]
async fn main() {
do_main().await;
}

/// An artificial "realistic" non-trivial example to demonstrate usage
async fn do_main() {
// Create some completely arbitrary "test data"
let test_data_size = 10;
let test_data: Vec<_> = (0..test_data_size).map(|x| (x, x.to_string())).collect();

let addr = env::args()
.nth(1)
.unwrap_or_else(|| "127.0.0.1:6379".to_string())
.parse()
.unwrap();
.unwrap_or_else(|| "127.0.0.1:6379".to_string());

let connection_builder = ConnectionBuilder::new(addr).expect("Cannot parse address");

let connection = client::paired_connect(addr)
let connection = connection_builder
.paired_connect()
.await
.expect("Cannot open connection");

let futures = test_data.into_iter().map(|data| {
let connection_inner = connection.clone();
let incr_f = connection.send(resp_array!["INCR", "realistic_test_ctr"]);
async move {
let ctr: String = incr_f.await.expect("Cannot increment");
let ctr: i64 = incr_f.await.expect("Cannot increment");

let key = format!("rt_{}", ctr);
let d_val = data.0.to_string();
Expand Down
29 changes: 20 additions & 9 deletions examples/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,44 @@
#[cfg(feature = "tokio02")]
extern crate tokio_02 as tokio;

#[cfg(feature = "tokio03")]
extern crate tokio_03 as tokio;

#[cfg(feature = "tokio10")]
extern crate tokio_10 as tokio;

use std::env;

use client::ConnectionBuilder;
use futures::StreamExt;

use redis_async::{client, resp::FromResp};
use redis_async::{client, protocol::FromResp};

#[cfg(feature = "with_tokio")]
#[tokio::main]
async fn main() {
do_main().await;
}

#[cfg(feature = "with_async_std")]
#[async_std::main]
async fn main() {
do_main().await;
}

async fn do_main() {
env_logger::init();
let topic = env::args()
.nth(1)
.unwrap_or_else(|| "test-topic".to_string());

let addr = env::args()
.nth(2)
.unwrap_or_else(|| "127.0.0.1:6379".to_string())
.parse()
.unwrap();
.unwrap_or_else(|| "127.0.0.1:6379".to_string());

let pubsub_con = client::pubsub_connect(addr)
let pubsub_con = ConnectionBuilder::new(addr)
.expect("Cannot parse address")
.pubsub_connect()
.await
.expect("Cannot connect to Redis");
.expect("Cannot open connection");

let mut msgs = pubsub_con
.subscribe(&topic)
.await
Expand Down
Loading