Skip to content

Commit 8bb2220

Browse files
committed
Update to service-0.4
1 parent 37d8121 commit 8bb2220

File tree

4 files changed

+36
-31
lines changed

4 files changed

+36
-31
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## [0.4.0-alpha.0] - 2022-xx-xx
4+
5+
* Upgrade to ntex-service-0.4
6+
37
## [0.3.3] - 2022-07-07
48

59
* pubsub support #5

Cargo.toml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntex-redis"
3-
version = "0.3.3"
3+
version = "0.4.0-alpha.0"
44
authors = ["ntex contributors <[email protected]>"]
55
description = "Redis client"
66
documentation = "https://docs.rs/ntex-redis"
@@ -12,13 +12,23 @@ exclude = [".gitignore", ".travis.yml", ".cargo/config"]
1212
edition = "2018"
1313

1414
[dependencies]
15-
ntex = "0.5.15"
15+
ntex = "0.6.0-alpha.0"
1616
itoa = "1.0.0"
1717
btoi = "0.4.2"
1818
log = "0.4"
1919
derive_more = "0.99"
2020

2121
[dev-dependencies]
2222
rand = "0.8"
23-
env_logger = "0.9"
24-
ntex = { version = "0.5", features = ["tokio"] }
23+
env_logger = "0.10"
24+
ntex = { version = "0.6.0-alpha.0", features = ["tokio"] }
25+
26+
[patch.crates-io]
27+
ntex = { git = "https://github.com/ntex-rs/ntex.git", branch = "service-0-4" }
28+
ntex-connect = { git = "https://github.com/ntex-rs/ntex.git", branch = "service-0-4" }
29+
ntex-io = { git = "https://github.com/ntex-rs/ntex.git", branch = "service-0-4" }
30+
ntex-service = { git = "https://github.com/ntex-rs/ntex.git", branch = "service-0-4" }
31+
ntex-util = { git = "https://github.com/ntex-rs/ntex.git", branch = "service-0-4" }
32+
ntex-tls = { git = "https://github.com/ntex-rs/ntex.git", branch = "service-0-4" }
33+
ntex-tokio = { git = "https://github.com/ntex-rs/ntex.git", branch = "service-0-4" }
34+
ntex-h2 = { git = "https://github.com/ntex-rs/ntex-h2.git", branch = "service-0-4" }

src/client.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl Client {
110110
impl Service<Request> for Client {
111111
type Response = Response;
112112
type Error = Error;
113-
type Future = Either<CommandResult, Ready<Response, Error>>;
113+
type Future<'f> = Either<CommandResult, Ready<Response, Error>>;
114114

115115
fn poll_ready(&self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
116116
if self.disconnect.poll_ready(cx).is_ready() {
@@ -120,7 +120,7 @@ impl Service<Request> for Client {
120120
}
121121
}
122122

123-
fn call(&self, req: Request) -> Self::Future {
123+
fn call(&self, req: Request) -> Self::Future<'_> {
124124
if let Err(e) = self.io.encode(req, &Codec) {
125125
Either::Right(Ready::Err(e))
126126
} else {

src/connector.rs

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::future::Future;
2-
31
use ntex::connect::{self, Address, Connect, Connector};
42
use ntex::io::IoBoxed;
53
use ntex::{service::Service, time::Seconds, util::ByteString, util::PoolId, util::PoolRef};
@@ -75,40 +73,33 @@ where
7573
T: Service<Connect<A>, Error = connect::ConnectError>,
7674
IoBoxed: From<T::Response>,
7775
{
78-
fn _connect(&self) -> impl Future<Output = Result<IoBoxed, ConnectError>> {
79-
let pool = self.pool;
80-
let passwords = self.passwords.clone();
76+
async fn _connect(&self) -> Result<IoBoxed, ConnectError> {
8177
let fut = self.connector.call(Connect::new(self.address.clone()));
78+
let io = IoBoxed::from(fut.await?);
79+
io.set_memory_pool(self.pool);
80+
io.set_disconnect_timeout(Seconds::ZERO.into());
8281

83-
async move {
84-
let io = IoBoxed::from(fut.await?);
85-
io.set_memory_pool(pool);
86-
io.set_disconnect_timeout(Seconds::ZERO.into());
87-
88-
if passwords.is_empty() {
89-
Ok(io)
90-
} else {
91-
let client = SimpleClient::new(io);
82+
if self.passwords.is_empty() {
83+
Ok(io)
84+
} else {
85+
let client = SimpleClient::new(io);
9286

93-
for password in passwords {
94-
if client.exec(cmd::Auth(password)).await? {
95-
return Ok(client.into_inner());
96-
}
87+
for password in &self.passwords {
88+
if client.exec(cmd::Auth(password)).await? {
89+
return Ok(client.into_inner());
9790
}
98-
Err(ConnectError::Unauthorized)
9991
}
92+
Err(ConnectError::Unauthorized)
10093
}
10194
}
10295

10396
/// Connect to redis server and create shared client
104-
pub fn connect(&self) -> impl Future<Output = Result<Client, ConnectError>> {
105-
let fut = self._connect();
106-
async move { fut.await.map(Client::new) }
97+
pub async fn connect(&self) -> Result<Client, ConnectError> {
98+
self._connect().await.map(Client::new)
10799
}
108100

109101
/// Connect to redis server and create simple client
110-
pub fn connect_simple(&self) -> impl Future<Output = Result<SimpleClient, ConnectError>> {
111-
let fut = self._connect();
112-
async move { fut.await.map(SimpleClient::new) }
102+
pub async fn connect_simple(&self) -> Result<SimpleClient, ConnectError> {
103+
self._connect().await.map(SimpleClient::new)
113104
}
114105
}

0 commit comments

Comments
 (0)