@@ -13,7 +13,9 @@ pub struct ClusterClientBuilder {
13
13
}
14
14
15
15
impl ClusterClientBuilder {
16
- /// Generate the base configuration for new Client.
16
+ /// Creates a new `ClusterClientBuilder` with the the provided initial_nodes.
17
+ ///
18
+ /// This is the same as `ClusterClient::builder(initial_nodes)`.
17
19
pub fn new < T : IntoConnectionInfo > ( initial_nodes : Vec < T > ) -> ClusterClientBuilder {
18
20
ClusterClientBuilder {
19
21
initial_nodes : initial_nodes
@@ -26,16 +28,26 @@ impl ClusterClientBuilder {
26
28
}
27
29
}
28
30
29
- fn build ( self ) -> RedisResult < ClusterClient > {
31
+ /// Creates a new [`ClusterClient`] with the parameters.
32
+ ///
33
+ /// This does not create connections to the Redis Cluster, but only performs some basic checks
34
+ /// on the initial nodes' URLs and passwords/usernames.
35
+ ///
36
+ /// # Errors
37
+ ///
38
+ /// Upon failure to parse initial nodes or if the initial nodes have different passwords or
39
+ /// usernames, an error is returned.
40
+ pub fn build ( self ) -> RedisResult < ClusterClient > {
30
41
let initial_nodes = self . initial_nodes ?;
42
+
31
43
let mut nodes = Vec :: with_capacity ( initial_nodes. len ( ) ) ;
32
44
let mut connection_info_password = None :: < String > ;
33
45
let mut connection_info_username = None :: < String > ;
34
46
35
47
for ( index, info) in initial_nodes. into_iter ( ) . enumerate ( ) {
36
48
if let ConnectionAddr :: Unix ( _) = info. addr {
37
49
return Err ( RedisError :: from ( ( ErrorKind :: InvalidClientConfig ,
38
- "This library cannot use unix socket because Redis's cluster command returns only cluster's IP and port." ) ) ) ;
50
+ "This library cannot use unix socket because Redis's cluster command returns only cluster's IP and port." ) ) ) ;
39
51
}
40
52
41
53
if self . password . is_none ( ) {
@@ -92,14 +104,8 @@ impl ClusterClientBuilder {
92
104
self
93
105
}
94
106
95
- /// Builds a [`ClusterClient`]. Despite the name, this does not actually open
96
- /// a connection to Redis Cluster, but will perform some basic checks of the initial
97
- /// nodes' URLs and passwords.
98
- ///
99
- /// # Errors
100
- ///
101
- /// Upon failure to parse initial nodes or if the initial nodes have different passwords,
102
- /// an error is returned.
107
+ /// Use `build()`.
108
+ #[ deprecated( since = "0.22.0" , note = "Use build()" ) ]
103
109
pub fn open ( self ) -> RedisResult < ClusterClient > {
104
110
self . build ( )
105
111
}
@@ -121,6 +127,24 @@ pub struct ClusterClient {
121
127
}
122
128
123
129
impl ClusterClient {
130
+ /// Creates a `ClusterClient` with the default parameters.
131
+ ///
132
+ /// This does not create connections to the Redis Cluster, but only performs some basic checks
133
+ /// on the initial nodes' URLs and passwords/usernames.
134
+ ///
135
+ /// # Errors
136
+ ///
137
+ /// Upon failure to parse initial nodes or if the initial nodes have different passwords or
138
+ /// usernames, an error is returned.
139
+ pub fn new < T : IntoConnectionInfo > ( initial_nodes : Vec < T > ) -> RedisResult < ClusterClient > {
140
+ ClusterClientBuilder :: new ( initial_nodes) . build ( )
141
+ }
142
+
143
+ /// Creates a [`ClusterClientBuilder`] with the the provided initial_nodes.
144
+ pub fn builder < T : IntoConnectionInfo > ( initial_nodes : Vec < T > ) -> ClusterClientBuilder {
145
+ ClusterClientBuilder :: new ( initial_nodes)
146
+ }
147
+
124
148
/// Opens connections to Redis Cluster nodes and returns a
125
149
/// [`ClusterConnection`].
126
150
///
@@ -136,22 +160,16 @@ impl ClusterClient {
136
160
)
137
161
}
138
162
139
- /// Create a [`ClusterClient`] with the default configuration. Despite the name,
140
- /// this does not actually open a connection to Redis Cluster, but only performs some basic
141
- /// checks of the initial nodes' URLs and passwords.
142
- ///
143
- /// # Errors
144
- ///
145
- /// Upon failure to parse initial nodes or if the initial nodes have different passwords,
146
- /// an error is returned.
163
+ /// Use `new()`.
164
+ #[ deprecated( since = "0.22.0" , note = "Use new()" ) ]
147
165
pub fn open < T : IntoConnectionInfo > ( initial_nodes : Vec < T > ) -> RedisResult < ClusterClient > {
148
- ClusterClientBuilder :: new ( initial_nodes) . open ( )
166
+ ClusterClient :: new ( initial_nodes)
149
167
}
150
168
}
151
169
152
170
impl Clone for ClusterClient {
153
171
fn clone ( & self ) -> ClusterClient {
154
- ClusterClient :: open ( self . initial_nodes . clone ( ) ) . unwrap ( )
172
+ ClusterClient :: new ( self . initial_nodes . clone ( ) ) . unwrap ( )
155
173
}
156
174
}
157
175
@@ -198,26 +216,26 @@ mod tests {
198
216
199
217
#[ test]
200
218
fn give_no_password ( ) {
201
- let client = ClusterClient :: open ( get_connection_data ( ) ) . unwrap ( ) ;
219
+ let client = ClusterClient :: new ( get_connection_data ( ) ) . unwrap ( ) ;
202
220
assert_eq ! ( client. password, None ) ;
203
221
}
204
222
205
223
#[ test]
206
224
fn give_password_by_initial_nodes ( ) {
207
- let client = ClusterClient :: open ( get_connection_data_with_password ( ) ) . unwrap ( ) ;
225
+ let client = ClusterClient :: new ( get_connection_data_with_password ( ) ) . unwrap ( ) ;
208
226
assert_eq ! ( client. password, Some ( "password" . to_string( ) ) ) ;
209
227
}
210
228
211
229
#[ test]
212
230
fn give_username_and_password_by_initial_nodes ( ) {
213
- let client = ClusterClient :: open ( get_connection_data_with_username_and_password ( ) ) . unwrap ( ) ;
231
+ let client = ClusterClient :: new ( get_connection_data_with_username_and_password ( ) ) . unwrap ( ) ;
214
232
assert_eq ! ( client. password, Some ( "password" . to_string( ) ) ) ;
215
233
assert_eq ! ( client. username, Some ( "user1" . to_string( ) ) ) ;
216
234
}
217
235
218
236
#[ test]
219
237
fn give_different_password_by_initial_nodes ( ) {
220
- let result = ClusterClient :: open ( vec ! [
238
+ let result = ClusterClient :: new ( vec ! [
221
239
"redis://:[email protected] :6379" ,
222
240
"redis://:[email protected] :6378" ,
223
241
"redis://:[email protected] :6377" ,
@@ -227,7 +245,7 @@ mod tests {
227
245
228
246
#[ test]
229
247
fn give_different_username_by_initial_nodes ( ) {
230
- let result = ClusterClient :: open ( vec ! [
248
+ let result = ClusterClient :: new ( vec ! [
231
249
"redis://user1:[email protected] :6379" ,
232
250
"redis://user2:[email protected] :6378" ,
233
251
"redis://user1:[email protected] :6377" ,
@@ -240,7 +258,7 @@ mod tests {
240
258
let client = ClusterClientBuilder :: new ( get_connection_data_with_password ( ) )
241
259
. password ( "pass" . to_string ( ) )
242
260
. username ( "user1" . to_string ( ) )
243
- . open ( )
261
+ . build ( )
244
262
. unwrap ( ) ;
245
263
assert_eq ! ( client. password, Some ( "pass" . to_string( ) ) ) ;
246
264
assert_eq ! ( client. username, Some ( "user1" . to_string( ) ) ) ;
0 commit comments