Skip to content

Commit 7451e02

Browse files
committed
Migrate to ntex 0.7
1 parent d41dfd7 commit 7451e02

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
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.5.0] - 2023-06-22
4+
5+
* Migrate to ntex 0.7
6+
37
## [0.4.1] - 2023-01-28
48

59
* Fix decode uncomple array data

Cargo.toml

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

1414
[dependencies]
15-
ntex = "0.6.2"
15+
ntex = "0.7.0"
1616
itoa = "1.0.0"
1717
btoi = "0.4.2"
1818
log = "0.4"
@@ -21,4 +21,4 @@ derive_more = "0.99"
2121
[dev-dependencies]
2222
rand = "0.8"
2323
env_logger = "0.10"
24-
ntex = { version = "0.6.2", features = ["tokio"] }
24+
ntex = { version = "0.7.0", features = ["tokio"] }

src/client.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cell::RefCell, fmt, future::Future, pin::Pin, rc::Rc, task::Context, t
33

44
use ntex::io::{IoBoxed, IoRef, OnDisconnect, RecvError};
55
use ntex::util::{poll_fn, ready, Either, Ready};
6-
use ntex::{channel::pool, service::Service};
6+
use ntex::{channel::pool, service::ServiceCtx, service::Service};
77

88
use super::cmd::Command;
99
use super::codec::{Codec, Request, Response};
@@ -82,7 +82,7 @@ impl Client {
8282
T: Command,
8383
{
8484
let is_open = !self.io.is_closed();
85-
let fut = self.call(cmd.to_request());
85+
let fut = self._call(cmd.to_request());
8686

8787
async move {
8888
if !is_open {
@@ -97,14 +97,24 @@ impl Client {
9797

9898
/// Delete all the keys of the currently selected DB.
9999
pub async fn flushdb(&self) -> Result<(), Error> {
100-
self.call("FLUSHDB".into()).await?;
100+
self._call("FLUSHDB".into()).await?;
101101
Ok(())
102102
}
103103

104104
/// Returns true if underlying transport is connected to redis
105105
pub fn is_connected(&self) -> bool {
106106
!self.io.is_closed()
107107
}
108+
109+
fn _call(&self, req: Request) -> Either<CommandResult, Ready<Response, Error>> {
110+
if let Err(e) = self.io.encode(req, &Codec) {
111+
Either::Right(Ready::Err(e))
112+
} else {
113+
let (tx, rx) = self.pool.channel();
114+
self.queue.borrow_mut().push_back(tx);
115+
Either::Left(CommandResult { rx })
116+
}
117+
}
108118
}
109119

110120
impl Service<Request> for Client {
@@ -120,14 +130,8 @@ impl Service<Request> for Client {
120130
}
121131
}
122132

123-
fn call(&self, req: Request) -> Self::Future<'_> {
124-
if let Err(e) = self.io.encode(req, &Codec) {
125-
Either::Right(Ready::Err(e))
126-
} else {
127-
let (tx, rx) = self.pool.channel();
128-
self.queue.borrow_mut().push_back(tx);
129-
Either::Left(CommandResult { rx })
130-
}
133+
fn call<'a>(&'a self, req: Request, _: ServiceCtx<'a, Self>) -> Self::Future<'a> {
134+
self._call(req)
131135
}
132136
}
133137

src/connector.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use ntex::connect::{self, Address, Connect, Connector};
2-
use ntex::io::IoBoxed;
3-
use ntex::{service::Service, time::Seconds, util::ByteString, util::PoolId, util::PoolRef};
2+
use ntex::service::{Pipeline, Service};
3+
use ntex::{io::IoBoxed, time::Seconds, util::ByteString, util::PoolId, util::PoolRef};
44

5-
use super::errors::ConnectError;
6-
use super::{cmd, Client, SimpleClient};
5+
use super::{cmd, errors::ConnectError, Client, SimpleClient};
76

87
/// Redis connector
98
pub struct RedisConnector<A, T> {
109
address: A,
11-
connector: T,
10+
connector: Pipeline<T>,
1211
passwords: Vec<ByteString>,
1312
pool: PoolRef,
1413
}
@@ -23,7 +22,7 @@ where
2322
RedisConnector {
2423
address,
2524
passwords: Vec::new(),
26-
connector: Connector::default(),
25+
connector: Pipeline::new(Connector::default()),
2726
pool: PoolId::P7.pool_ref(),
2827
}
2928
}
@@ -59,7 +58,7 @@ where
5958
IoBoxed: From<U::Response>,
6059
{
6160
RedisConnector {
62-
connector,
61+
connector: Pipeline::new(connector),
6362
address: self.address,
6463
passwords: self.passwords,
6564
pool: self.pool,

0 commit comments

Comments
 (0)