1515import redis .clients .jedis .ConnectionPool ;
1616import redis .clients .jedis .JedisClusterInfoCache ;
1717import redis .clients .jedis .exceptions .JedisClusterOperationException ;
18- import redis .clients .jedis .exceptions .JedisConnectionException ;
1918import redis .clients .jedis .exceptions .JedisException ;
2019
2120public class ClusterConnectionProvider implements ConnectionProvider {
@@ -34,19 +33,30 @@ public ClusterConnectionProvider(Set<HostAndPort> clusterNodes, JedisClientConfi
3433 }
3534
3635 private void initializeSlotsCache (Set <HostAndPort > startNodes , JedisClientConfig clientConfig ) {
36+ if (startNodes .isEmpty ()) {
37+ throw new JedisClusterOperationException ("No nodes to initialize cluster slots cache." );
38+ }
39+
3740 ArrayList <HostAndPort > startNodeList = new ArrayList <>(startNodes );
3841 Collections .shuffle (startNodeList );
3942
43+ JedisException firstException = null ;
4044 for (HostAndPort hostAndPort : startNodeList ) {
4145 try (Connection jedis = new Connection (hostAndPort , clientConfig )) {
4246 cache .discoverClusterNodesAndSlots (jedis );
4347 return ;
4448 } catch (JedisException e ) {
49+ if (firstException == null ) {
50+ firstException = e ;
51+ }
4552 // try next nodes
4653 }
4754 }
4855
49- throw new JedisClusterOperationException ("Could not initialize cluster slots cache." );
56+ JedisClusterOperationException uninitializedException
57+ = new JedisClusterOperationException ("Could not initialize cluster slots cache." );
58+ uninitializedException .addSuppressed (firstException );
59+ throw uninitializedException ;
5060 }
5161
5262 @ Override
0 commit comments