Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/main/java/redis/clients/jedis/JedisCluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import redis.clients.jedis.commands.MultiKeyJedisClusterCommands;
import redis.clients.util.KeyMergeUtil;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -23,6 +24,36 @@ public static enum Reset {
SOFT, HARD
}

public JedisCluster(HostAndPort node) {
this(Collections.singleton(node), DEFAULT_TIMEOUT);
}

public JedisCluster(HostAndPort node, int timeout) {
this(Collections.singleton(node), timeout, DEFAULT_MAX_REDIRECTIONS);
}

public JedisCluster(HostAndPort node, int timeout, int maxRedirections) {
this(Collections.singleton(node), timeout, maxRedirections, new GenericObjectPoolConfig());
}

public JedisCluster(HostAndPort node, final GenericObjectPoolConfig poolConfig) {
this(Collections.singleton(node), DEFAULT_TIMEOUT, DEFAULT_MAX_REDIRECTIONS, poolConfig);
}

public JedisCluster(HostAndPort node, int timeout, final GenericObjectPoolConfig poolConfig) {
this(Collections.singleton(node), timeout, DEFAULT_MAX_REDIRECTIONS, poolConfig);
}

public JedisCluster(HostAndPort node, int timeout, int maxRedirections,
final GenericObjectPoolConfig poolConfig) {
this(Collections.singleton(node), timeout, maxRedirections, poolConfig);
}

public JedisCluster(HostAndPort node, int connectionTimeout, int soTimeout,
int maxRedirections, final GenericObjectPoolConfig poolConfig) {
super(Collections.singleton(node), connectionTimeout, soTimeout, maxRedirections, poolConfig);
}

public JedisCluster(Set<HostAndPort> nodes) {
this(nodes, DEFAULT_TIMEOUT);
}
Expand Down
11 changes: 10 additions & 1 deletion src/test/java/redis/clients/jedis/tests/JedisClusterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ public void testDiscoverNodesAutomatically() {
jedisClusterNode.add(new HostAndPort("127.0.0.1", 7379));
JedisCluster jc = new JedisCluster(jedisClusterNode);
assertEquals(3, jc.getClusterNodes().size());

JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379));
assertEquals(3, jc2.getClusterNodes().size());
}

@Test
public void testCalculateConnectionPerSlot() {
Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
Expand All @@ -138,6 +141,12 @@ public void testCalculateConnectionPerSlot() {
jc.set("test", "test");
assertEquals("bar", node3.get("foo"));
assertEquals("test", node2.get("test"));

JedisCluster jc2 = new JedisCluster(new HostAndPort("127.0.0.1", 7379));
jc2.set("foo", "bar");
jc2.set("test", "test");
assertEquals("bar", node3.get("foo"));
assertEquals("test", node2.get("test"));
}

@Test
Expand Down