MasterSlave consistency and old mode compatibility with shard names
This commit is contained in:
@@ -22,11 +22,12 @@ public class JedisShardInfo extends ShardInfo<Jedis> {
|
||||
public String toString() {
|
||||
return host + ":" + port + "*" + getWeight();
|
||||
}
|
||||
|
||||
|
||||
private int timeout;
|
||||
private String host;
|
||||
private int port;
|
||||
private String password = null;
|
||||
private String name = null;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
@@ -39,15 +40,27 @@ public class JedisShardInfo extends ShardInfo<Jedis> {
|
||||
public JedisShardInfo(String host) {
|
||||
this(host, Protocol.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, String name) {
|
||||
this(host, Protocol.DEFAULT_PORT, name);
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, int port) {
|
||||
this(host, port, 2000);
|
||||
}
|
||||
|
||||
|
||||
public JedisShardInfo(String host, int port, String name) {
|
||||
this(host, port, 2000, name);
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, int port, int timeout) {
|
||||
this(host, port, timeout, Sharded.DEFAULT_WEIGHT);
|
||||
}
|
||||
|
||||
|
||||
public JedisShardInfo(String host, int port, int timeout, String name) {
|
||||
this(host, port, timeout, Sharded.DEFAULT_WEIGHT);
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public JedisShardInfo(String host, int port, int timeout, int weight) {
|
||||
super(weight);
|
||||
this.host = host;
|
||||
@@ -70,6 +83,10 @@ public class JedisShardInfo extends ShardInfo<Jedis> {
|
||||
public void setTimeout(int timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Jedis createResource() {
|
||||
|
||||
@@ -15,4 +15,6 @@ public abstract class ShardInfo<T> {
|
||||
}
|
||||
|
||||
protected abstract T createResource();
|
||||
|
||||
public abstract String getName();
|
||||
}
|
||||
|
||||
@@ -56,7 +56,10 @@ public class Sharded<R, S extends ShardInfo<R>> {
|
||||
for (int i = 0; i != shards.size(); ++i) {
|
||||
final S shardInfo = shards.get(i);
|
||||
for (int n = 0; n < 160 * shardInfo.getWeight(); n++) {
|
||||
nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n), shardInfo);
|
||||
if (shardInfo.getName() == null)
|
||||
nodes.put(this.algo.hash("SHARD-" + i + "-NODE-" + n), shardInfo);
|
||||
else
|
||||
nodes.put(this.algo.hash(shardInfo.getName() + "*" + shardInfo.getWeight() + n), shardInfo);
|
||||
}
|
||||
resources.put(shardInfo, shardInfo.createResource());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user