Skip to content

Commit 02c49d8

Browse files
committed
memory pools support
1 parent 77e8aae commit 02c49d8

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
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.2.4] - 2021-12-02
4+
5+
* Add memory pools support
6+
37
## [0.2.3] - 2021-09-03
48

59
* Fix panic during protocol decoding

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntex-redis"
3-
version = "0.2.3"
3+
version = "0.2.4"
44
authors = ["ntex contributors <[email protected]>"]
55
description = "Redis client"
66
documentation = "https://docs.rs/ntex-redis"
@@ -21,7 +21,7 @@ openssl = ["ntex/openssl"]
2121
rustls = ["ntex/rustls"]
2222

2323
[dependencies]
24-
ntex = "0.4.0-b.11"
24+
ntex = "0.4.11"
2525
itoa = "0.4.5"
2626
btoi = "0.4.2"
2727
log = "0.4"

src/connector.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{cell::RefCell, future::Future, rc::Rc};
33
use ntex::codec::{AsyncRead, AsyncWrite};
44
use ntex::connect::{self, Address, Connect, Connector};
55
use ntex::framed::{ReadTask, State, WriteTask};
6-
use ntex::{service::Service, time::Seconds, util::ByteString};
6+
use ntex::{service::Service, time::Seconds, util::ByteString, util::PoolId, util::PoolRef};
77

88
#[cfg(feature = "openssl")]
99
use ntex::connect::openssl::{OpensslConnector, SslConnector};
@@ -19,9 +19,7 @@ pub struct RedisConnector<A, T> {
1919
address: A,
2020
connector: T,
2121
passwords: Vec<ByteString>,
22-
lw: u16,
23-
read_hw: u16,
24-
write_hw: u16,
22+
pool: PoolRef,
2523
}
2624

2725
impl<A> RedisConnector<A, ()>
@@ -35,9 +33,7 @@ where
3533
address,
3634
passwords: Vec::new(),
3735
connector: Connector::default(),
38-
lw: 1024,
39-
read_hw: 16 * 1024,
40-
write_hw: 16 * 1024,
36+
pool: PoolId::P7.pool_ref(),
4137
}
4238
}
4339
}
@@ -58,19 +54,27 @@ where
5854
self
5955
}
6056

57+
/// Set memory pool.
58+
///
59+
/// Use specified memory pool for memory allocations. By default P7
60+
/// memory pool is used.
61+
pub fn memory_pool(mut self, id: PoolId) -> Self {
62+
self.pool = id.pool_ref();
63+
self
64+
}
65+
66+
#[doc(hidden)]
67+
#[deprecated(since = "0.2.4", note = "Use memory pool config")]
6168
#[inline]
6269
/// Set read/write buffer params
6370
///
6471
/// By default read buffer is 16kb, write buffer is 16kb
6572
pub fn buffer_params(
66-
mut self,
67-
max_read_buf_size: u16,
68-
max_write_buf_size: u16,
69-
min_buf_size: u16,
73+
self,
74+
_max_read_buf_size: u16,
75+
_max_write_buf_size: u16,
76+
_min_buf_size: u16,
7077
) -> Self {
71-
self.read_hw = max_read_buf_size;
72-
self.write_hw = max_write_buf_size;
73-
self.lw = min_buf_size;
7478
self
7579
}
7680

@@ -84,9 +88,7 @@ where
8488
connector,
8589
address: self.address,
8690
passwords: self.passwords,
87-
read_hw: self.read_hw,
88-
write_hw: self.write_hw,
89-
lw: self.lw,
91+
pool: self.pool,
9092
}
9193
}
9294

@@ -97,9 +99,7 @@ where
9799
address: self.address,
98100
passwords: self.passwords,
99101
connector: OpensslConnector::new(connector),
100-
read_hw: self.read_hw,
101-
write_hw: self.write_hw,
102-
lw: self.lw,
102+
pool: self.pool,
103103
}
104104
}
105105

@@ -113,24 +113,21 @@ where
113113
address: self.address,
114114
passwords: self.passwords,
115115
connector: RustlsConnector::new(config),
116-
read_hw: self.read_hw,
117-
write_hw: self.write_hw,
118-
lw: self.lw,
116+
pool: self.pool,
119117
}
120118
}
121119

122120
/// Connect to redis server and create shared client
123121
pub fn connect(&self) -> impl Future<Output = Result<Client, ConnectError>> {
124-
let read_hw = self.read_hw;
125-
let write_hw = self.write_hw;
126-
let lw = self.lw;
122+
let pool = self.pool;
127123
let passwords = self.passwords.clone();
128124
let fut = self.connector.call(Connect::new(self.address.clone()));
129125

130126
async move {
131127
let io = fut.await?;
132128

133-
let state = State::with_params(read_hw, write_hw, lw, Seconds::ZERO);
129+
let state = State::with_memory_pool(pool);
130+
state.set_disconnect_timeout(Seconds::ZERO);
134131
let io = Rc::new(RefCell::new(io));
135132
ntex::rt::spawn(ReadTask::new(io.clone(), state.clone()));
136133
ntex::rt::spawn(WriteTask::new(io, state.clone()));
@@ -152,16 +149,15 @@ where
152149

153150
/// Connect to redis server and create simple client
154151
pub fn connect_simple(&self) -> impl Future<Output = Result<SimpleClient, ConnectError>> {
155-
let read_hw = self.read_hw;
156-
let write_hw = self.write_hw;
157-
let lw = self.lw;
152+
let pool = self.pool;
158153
let passwords = self.passwords.clone();
159154
let fut = self.connector.call(Connect::new(self.address.clone()));
160155

161156
async move {
162157
let io = fut.await?;
163158

164-
let state = State::with_params(read_hw, write_hw, lw, Seconds::ZERO);
159+
let state = State::with_memory_pool(pool);
160+
state.set_disconnect_timeout(Seconds::ZERO);
165161
let io = Rc::new(RefCell::new(io));
166162
ntex::rt::spawn(ReadTask::new(io.clone(), state.clone()));
167163
ntex::rt::spawn(WriteTask::new(io, state.clone()));

0 commit comments

Comments
 (0)