add url support

This commit is contained in:
Jonathan Leibiusky
2012-08-01 16:49:44 -03:00
parent 35a7677eb9
commit 8f9763a7e9
8 changed files with 231 additions and 53 deletions

View File

@@ -1,11 +1,13 @@
package redis.clients.jedis;
import java.net.URI;
import redis.clients.util.ShardInfo;
import redis.clients.util.Sharded;
public class JedisShardInfo extends ShardInfo<Jedis> {
public String toString() {
return host + ":" + port + "*" + getWeight();
return host + ":" + port + "*" + getWeight();
}
private int timeout;
@@ -15,67 +17,83 @@ public class JedisShardInfo extends ShardInfo<Jedis> {
private String name = null;
public String getHost() {
return host;
return host;
}
public int getPort() {
return port;
return port;
}
public JedisShardInfo(String host) {
this(host, Protocol.DEFAULT_PORT);
super(Sharded.DEFAULT_WEIGHT);
URI uri = URI.create(host);
if (uri.getScheme() != null && uri.getScheme().equals("redis")) {
this.host = uri.getHost();
this.port = uri.getPort();
this.password = uri.getUserInfo().split(":", 2)[1];
} else {
this.host = host;
this.port = Protocol.DEFAULT_PORT;
}
}
public JedisShardInfo(String host, String name) {
this(host, Protocol.DEFAULT_PORT, name);
this(host, Protocol.DEFAULT_PORT, name);
}
public JedisShardInfo(String host, int port) {
this(host, port, 2000);
this(host, port, 2000);
}
public JedisShardInfo(String host, int port, String name) {
this(host, port, 2000, name);
this(host, port, 2000, name);
}
public JedisShardInfo(String host, int port, int timeout) {
this(host, port, timeout, Sharded.DEFAULT_WEIGHT);
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;
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;
this.port = port;
this.timeout = timeout;
super(weight);
this.host = host;
this.port = port;
this.timeout = timeout;
}
public JedisShardInfo(URI uri) {
super(Sharded.DEFAULT_WEIGHT);
this.host = uri.getHost();
this.port = uri.getPort();
this.password = uri.getUserInfo().split(":", 2)[1];
}
public String getPassword() {
return password;
return password;
}
public void setPassword(String auth) {
this.password = auth;
this.password = auth;
}
public int getTimeout() {
return timeout;
return timeout;
}
public void setTimeout(int timeout) {
this.timeout = timeout;
this.timeout = timeout;
}
public String getName() {
return name;
return name;
}
@Override
public Jedis createResource() {
return new Jedis(this);
return new Jedis(this);
}
}