diff --git a/src/main/java/redis/clients/jedis/JedisCluster.java b/src/main/java/redis/clients/jedis/JedisCluster.java index 68d8f4205f..4d6b672272 100644 --- a/src/main/java/redis/clients/jedis/JedisCluster.java +++ b/src/main/java/redis/clients/jedis/JedisCluster.java @@ -19,16 +19,38 @@ public class JedisCluster extends UnifiedJedis { * Default timeout in milliseconds. */ public static final int DEFAULT_TIMEOUT = 2000; + + /** + * Default amount of attempts for executing a command + */ public static final int DEFAULT_MAX_ATTEMPTS = 5; + /** + * Creates a JedisCluster instance. The provided node is used to make the first contact with the cluster.
+ * Here, the default timeout of {@value JedisCluster#DEFAULT_TIMEOUT} ms is being used with {@value JedisCluster#DEFAULT_MAX_ATTEMPTS} maximum attempts. + * @param node Node to first connect to. + */ public JedisCluster(HostAndPort node) { this(Collections.singleton(node)); } + /** + * Creates a JedisCluster instance. The provided node is used to make the first contact with the cluster.
+ * Here, the default timeout of {@value JedisCluster#DEFAULT_TIMEOUT} ms is being used with {@value JedisCluster#DEFAULT_MAX_ATTEMPTS} maximum attempts. + * @param node Node to first connect to. + * @param timeout connection and socket timeout in milliseconds. + */ public JedisCluster(HostAndPort node, int timeout) { this(Collections.singleton(node), timeout); } + /** + * Creates a JedisCluster instance. The provided node is used to make the first contact with the cluster.
+ * You can specify the timeout and the maximum attempts. + * @param node Node to first connect to. + * @param timeout connection and socket timeout in milliseconds. + * @param maxAttempts maximum attempts for executing a command. + */ public JedisCluster(HostAndPort node, int timeout, int maxAttempts) { this(Collections.singleton(node), timeout, maxAttempts); } @@ -89,14 +111,32 @@ public JedisCluster(HostAndPort node, final JedisClientConfig clientConfig, int this(Collections.singleton(node), clientConfig, maxAttempts, poolConfig); } + /** + * Creates a JedisCluster with multiple entry points. + * Here, the default timeout of {@value JedisCluster#DEFAULT_TIMEOUT} ms is being used with {@value JedisCluster#DEFAULT_MAX_ATTEMPTS} maximum attempts. + * @param nodes Nodes to connect to. + */ public JedisCluster(Set nodes) { this(nodes, DEFAULT_TIMEOUT); } + /** + * Creates a JedisCluster with multiple entry points. + * Here, the default timeout of {@value JedisCluster#DEFAULT_TIMEOUT} ms is being used with {@value JedisCluster#DEFAULT_MAX_ATTEMPTS} maximum attempts. + * @param nodes Nodes to connect to. + * @param timeout connection and socket timeout in milliseconds. + */ public JedisCluster(Set nodes, int timeout) { this(nodes, DefaultJedisClientConfig.builder().timeoutMillis(timeout).build()); } + /** + * Creates a JedisCluster with multiple entry points.
+ * You can specify the timeout and the maximum attempts. + * @param nodes Nodes to connect to. + * @param timeout connection and socket timeout in milliseconds. + * @param maxAttempts maximum attempts for executing a command. + */ public JedisCluster(Set nodes, int timeout, int maxAttempts) { this(nodes, DefaultJedisClientConfig.builder().timeoutMillis(timeout).build(), maxAttempts); } @@ -206,6 +246,19 @@ public JedisCluster(Set clusterNodes, JedisClientConfig clientConfi maxAttempts, maxTotalRetriesDuration, clientConfig.getRedisProtocol()); } + /** + * Creates a JedisCluster with multiple entry points.
+ * You can specify the timeout and the maximum attempts.
+ * + * Additionally, you are free to provide a {@link JedisClientConfig} instance.
+ * You can use the {@link DefaultJedisClientConfig#builder()} builder pattern to customize your configuration, including socket timeouts, + * username and passwords as well as SSL related parameters. + * + * @param clusterNodes Nodes to connect to. + * @param clientConfig Client configuration parameters. + * @param maxAttempts maximum attempts for executing a command. + * @param maxTotalRetriesDuration Maximum time used for reconnecting. + */ public JedisCluster(Set clusterNodes, JedisClientConfig clientConfig, int maxAttempts, Duration maxTotalRetriesDuration, GenericObjectPoolConfig poolConfig) { this(new ClusterConnectionProvider(clusterNodes, clientConfig, poolConfig), maxAttempts, maxTotalRetriesDuration, @@ -223,10 +276,20 @@ private JedisCluster(ClusterConnectionProvider provider, int maxAttempts, Durati super(provider, maxAttempts, maxTotalRetriesDuration, protocol); } + /** + * Returns all nodes that were configured to connect to in key-value pairs ({@link Map}).
+ * Key is the HOST:PORT and the value is the connection pool. + * @return the map of all connections. + */ public Map getClusterNodes() { return ((ClusterConnectionProvider) provider).getNodes(); } + /** + * Returns the connection for one of the 16,384 slots. + * @param slot the slot to retrieve the connection for. + * @return connection of the provided slot. {@code close()} of this connection must be called after use. + */ public Connection getConnectionFromSlot(int slot) { return ((ClusterConnectionProvider) provider).getConnectionFromSlot(slot); }