1
1
/*
2
- * Copyright 2015 the original author or authors.
2
+ * Copyright 2015-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
61
61
62
62
import com .lambdaworks .redis .KeyValue ;
63
63
import com .lambdaworks .redis .RedisException ;
64
+ import com .lambdaworks .redis .RedisURI ;
64
65
import com .lambdaworks .redis .api .StatefulConnection ;
65
66
import com .lambdaworks .redis .cluster .RedisClusterClient ;
66
67
import com .lambdaworks .redis .cluster .SlotHash ;
@@ -87,36 +88,46 @@ public class LettuceClusterConnection extends LettuceConnection
87
88
private final RedisClusterClient clusterClient ;
88
89
private ClusterCommandExecutor clusterCommandExecutor ;
89
90
private ClusterTopologyProvider topologyProvider ;
90
- private final boolean disposeClusterCommandExecutorOnClose ;
91
+ private boolean disposeClusterCommandExecutorOnClose ;
91
92
92
93
/**
93
- * Creates new {@link LettuceClusterConnection} using {@link RedisClusterClient}.
94
+ * Creates new {@link LettuceClusterConnection} using {@link RedisClusterClient} with default
95
+ * {@link RedisURI#DEFAULT_TIMEOUT timeout} and a fresh {@link ClusterCommandExecutor} that gets destroyed on close.
94
96
*
95
97
* @param clusterClient must not be {@literal null}.
96
98
*/
97
99
public LettuceClusterConnection (RedisClusterClient clusterClient ) {
98
100
99
- super (null , 100 , clusterClient , null , 0 );
101
+ this (clusterClient , RedisURI .DEFAULT_TIMEOUT ,
102
+ new ClusterCommandExecutor (new LettuceClusterTopologyProvider (clusterClient ),
103
+ new LettuceClusterNodeResourceProvider (clusterClient ), exceptionConverter ));
100
104
101
- Assert .notNull (clusterClient , "RedisClusterClient must not be null." );
102
-
103
- this .clusterClient = clusterClient ;
104
- topologyProvider = new LettuceClusterTopologyProvider (clusterClient );
105
- clusterCommandExecutor = new ClusterCommandExecutor (topologyProvider ,
106
- new LettuceClusterNodeResourceProvider (clusterClient ), exceptionConverter );
107
- disposeClusterCommandExecutorOnClose = true ;
105
+ this .disposeClusterCommandExecutorOnClose = true ;
108
106
}
109
107
110
108
/**
111
- * Creates new {@link LettuceClusterConnection} using {@link RedisClusterClient} running commands across the cluster
112
- * via given {@link ClusterCommandExecutor}.
109
+ * Creates new {@link LettuceClusterConnection} with default {@link RedisURI#DEFAULT_TIMEOUT timeout} using
110
+ * {@link RedisClusterClient} running commands across the cluster via given {@link ClusterCommandExecutor}.
113
111
*
114
112
* @param clusterClient must not be {@literal null}.
115
113
* @param executor must not be {@literal null}.
116
114
*/
117
115
public LettuceClusterConnection (RedisClusterClient clusterClient , ClusterCommandExecutor executor ) {
116
+ this (clusterClient , RedisURI .DEFAULT_TIMEOUT , executor );
117
+ }
118
+
119
+ /**
120
+ * Creates new {@link LettuceClusterConnection} with given command {@code timeout} using {@link RedisClusterClient}
121
+ * running commands across the cluster via given {@link ClusterCommandExecutor}.
122
+ *
123
+ * @param clusterClient must not be {@literal null}.
124
+ * @param timeout command timeout (in milliseconds)
125
+ * @param executor must not be {@literal null}.
126
+ * @since 1.8.7
127
+ */
128
+ public LettuceClusterConnection (RedisClusterClient clusterClient , long timeout , ClusterCommandExecutor executor ) {
118
129
119
- super (null , 100 , clusterClient , null , 0 );
130
+ super (null , timeout , clusterClient , null , 0 );
120
131
121
132
Assert .notNull (clusterClient , "RedisClusterClient must not be null." );
122
133
Assert .notNull (executor , "ClusterCommandExecutor must not be null." );
0 commit comments