18
18
import java .io .IOException ;
19
19
import java .util .List ;
20
20
21
- import com .lambdaworks .redis .RedisClient ;
22
- import com .lambdaworks .redis .RedisSentinelAsyncConnection ;
23
- import com .lambdaworks .redis .RedisURI ;
24
- import com .lambdaworks .redis .resource .ClientResources ;
25
21
import org .springframework .data .redis .ExceptionTranslationStrategy ;
26
22
import org .springframework .data .redis .FallbackExceptionTranslationStrategy ;
27
23
import org .springframework .data .redis .connection .NamedNode ;
30
26
import org .springframework .data .redis .connection .RedisServer ;
31
27
import org .springframework .util .Assert ;
32
28
29
+ import com .lambdaworks .redis .RedisClient ;
30
+ import com .lambdaworks .redis .RedisSentinelAsyncConnection ;
31
+ import com .lambdaworks .redis .RedisURI .Builder ;
32
+ import com .lambdaworks .redis .resource .ClientResources ;
33
+
33
34
/**
34
35
* @author Christoph Strobl
35
36
* @author Mark Paluch
@@ -45,6 +46,7 @@ public class LettuceSentinelConnection implements RedisSentinelConnection {
45
46
46
47
/**
47
48
* Creates a {@link LettuceSentinelConnection} with a dedicated client for a supplied {@link RedisNode}.
49
+ *
48
50
* @param sentinel The sentinel to connect to.
49
51
*/
50
52
public LettuceSentinelConnection (RedisNode sentinel ) {
@@ -53,31 +55,38 @@ public LettuceSentinelConnection(RedisNode sentinel) {
53
55
54
56
/**
55
57
* Creates a {@link LettuceSentinelConnection} with a client for the supplied {@code host} and {@code port}.
56
- * @param host hostname must not be {@literal null}
57
- * @param port sentinel port
58
+ *
59
+ * @param host must not be {@literal null}.
60
+ * @param port sentinel port.
58
61
*/
59
62
public LettuceSentinelConnection (String host , int port ) {
63
+
60
64
Assert .notNull (host , "Cannot create LettuceSentinelConnection using 'null' as host." );
61
- redisClient = RedisClient .create (new RedisURI .Builder ().redis (host , port ).build ());
65
+
66
+ redisClient = RedisClient .create (Builder .redis (host , port ).build ());
62
67
init ();
63
68
}
64
69
65
70
/**
66
71
* Creates a {@link LettuceSentinelConnection} with a client for the supplied {@code host} and {@code port} and reuse
67
- * existing {@code clientResources}.
68
- * @param clientResources must not be {@literal null}
69
- * @param host hostname must not be {@literal null}
70
- * @param port sentinel port
72
+ * existing {@link ClientResources}.
73
+ *
74
+ * @param host must not be {@literal null}.
75
+ * @param port sentinel port.
76
+ * @param clientResources must not be {@literal null}.
71
77
*/
72
- public LettuceSentinelConnection (ClientResources clientResources , String host , int port ) {
78
+ public LettuceSentinelConnection (String host , int port , ClientResources clientResources ) {
79
+
73
80
Assert .notNull (clientResources , "Cannot create LettuceSentinelConnection using 'null' as ClientResources." );
74
81
Assert .notNull (host , "Cannot create LettuceSentinelConnection using 'null' as host." );
75
- redisClient = RedisClient .create (clientResources , new RedisURI .Builder ().redis (host , port ).build ());
82
+
83
+ redisClient = RedisClient .create (clientResources , Builder .redis (host , port ).build ());
76
84
init ();
77
85
}
78
86
79
87
/**
80
88
* Creates a {@link LettuceSentinelConnection} using a supplied {@link RedisClient}.
89
+ *
81
90
* @param redisClient
82
91
*/
83
92
public LettuceSentinelConnection (RedisClient redisClient ) {
@@ -89,6 +98,7 @@ public LettuceSentinelConnection(RedisClient redisClient) {
89
98
90
99
/**
91
100
* Creates a {@link LettuceSentinelConnection} using a supplied redis connection.
101
+ *
92
102
* @param connection native Lettuce connection, must not be {@literal null}
93
103
*/
94
104
protected LettuceSentinelConnection (RedisSentinelAsyncConnection <String , String > connection ) {
@@ -181,8 +191,7 @@ public void monitor(RedisServer server) {
181
191
Assert .hasText (server .getHost (), "Host must not be 'null' for server to monitor." );
182
192
Assert .notNull (server .getPort (), "Port must not be 'null' for server to monitor." );
183
193
Assert .notNull (server .getQuorum (), "Quorum must not be 'null' for server to monitor." );
184
- connection .monitor (server .getName (), server .getHost (), server .getPort ().intValue (), server .getQuorum ()
185
- .intValue ());
194
+ connection .monitor (server .getName (), server .getHost (), server .getPort ().intValue (), server .getQuorum ().intValue ());
186
195
}
187
196
188
197
/*
@@ -194,7 +203,7 @@ public void close() throws IOException {
194
203
connection .close ();
195
204
connection = null ;
196
205
197
- if (redisClient != null ) {
206
+ if (redisClient != null ) {
198
207
redisClient .shutdown ();
199
208
}
200
209
}
@@ -209,7 +218,6 @@ private RedisSentinelAsyncConnection<String, String> connectSentinel() {
209
218
return redisClient .connectSentinelAsync ();
210
219
}
211
220
212
-
213
221
@ Override
214
222
public boolean isOpen () {
215
223
return connection != null && connection .isOpen ();
0 commit comments