Merge branch 'making_jedis_pool_cdi_compatible' of https://github.com/nykolaslima/jedis into nykolaslima-making_jedis_pool_cdi_compatible

This commit is contained in:
Jungtaek Lim
2014-10-09 08:35:06 +09:00
7 changed files with 34 additions and 16 deletions

View File

@@ -48,6 +48,10 @@ public class BinaryClient extends Connection {
return isInWatch; return isInWatch;
} }
public BinaryClient() {
super(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
}
public BinaryClient(final String host) { public BinaryClient(final String host) {
super(host); super(host);
} }

View File

@@ -27,6 +27,10 @@ public class BinaryJedis implements BasicCommands, BinaryJedisCommands,
protected Transaction transaction = null; protected Transaction transaction = null;
protected Pipeline pipeline = null; protected Pipeline pipeline = null;
public BinaryJedis() {
this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
}
public BinaryJedis(final String host) { public BinaryJedis(final String host) {
URI uri = URI.create(host); URI uri = URI.create(host);
if (uri.getScheme() != null && uri.getScheme().equals("redis")) { if (uri.getScheme() != null && uri.getScheme().equals("redis")) {

View File

@@ -12,6 +12,11 @@ import redis.clients.jedis.JedisCluster.Reset;
import redis.clients.util.SafeEncoder; import redis.clients.util.SafeEncoder;
public class Client extends BinaryClient implements Commands { public class Client extends BinaryClient implements Commands {
public Client() {
super(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
}
public Client(final String host) { public Client(final String host) {
super(host); super(host);
} }

View File

@@ -16,15 +16,28 @@ import redis.clients.util.RedisOutputStream;
import redis.clients.util.SafeEncoder; import redis.clients.util.SafeEncoder;
public class Connection implements Closeable { public class Connection implements Closeable {
private String host; private String host;
private int port = Protocol.DEFAULT_PORT; private int port = Protocol.DEFAULT_PORT;
private Socket socket; private Socket socket;
private RedisOutputStream outputStream; private RedisOutputStream outputStream;
private RedisInputStream inputStream; private RedisInputStream inputStream;
private int timeout = Protocol.DEFAULT_TIMEOUT; private int timeout = Protocol.DEFAULT_TIMEOUT;
private boolean broken = false; private boolean broken = false;
public Connection() {
this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
}
public Connection(final String host) {
this.host = host;
}
public Connection(final String host, final int port) {
this.host = host;
this.port = port;
}
public Socket getSocket() { public Socket getSocket() {
return socket; return socket;
} }
@@ -60,11 +73,6 @@ public class Connection implements Closeable {
} }
} }
public Connection(final String host) {
super();
this.host = host;
}
protected Connection sendCommand(final Command cmd, final String... args) { protected Connection sendCommand(final Command cmd, final String... args) {
final byte[][] bargs = new byte[args.length][]; final byte[][] bargs = new byte[args.length][];
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
@@ -97,12 +105,6 @@ public class Connection implements Closeable {
} }
} }
public Connection(final String host, final int port) {
super();
this.host = host;
this.port = port;
}
public String getHost() { public String getHost() {
return host; return host;
} }
@@ -119,10 +121,6 @@ public class Connection implements Closeable {
this.port = port; this.port = port;
} }
public Connection() {
}
public void connect() { public void connect() {
if (!isConnected()) { if (!isConnected()) {
try { try {

View File

@@ -23,6 +23,8 @@ public class Jedis extends BinaryJedis implements JedisCommands,
protected Pool<Jedis> dataSource = null; protected Pool<Jedis> dataSource = null;
public Jedis() {}
public Jedis(final String host) { public Jedis(final String host) {
super(host); super(host);
} }

View File

@@ -10,6 +10,10 @@ import redis.clients.util.Pool;
public class JedisPool extends Pool<Jedis> { public class JedisPool extends Pool<Jedis> {
public JedisPool() {
this(Protocol.DEFAULT_HOST, Protocol.DEFAULT_PORT);
}
public JedisPool(final GenericObjectPoolConfig poolConfig, final String host) { public JedisPool(final GenericObjectPoolConfig poolConfig, final String host) {
this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, this(poolConfig, host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT,
null, Protocol.DEFAULT_DATABASE, null); null, Protocol.DEFAULT_DATABASE, null);

View File

@@ -18,6 +18,7 @@ public final class Protocol {
private static final String ASK_RESPONSE = "ASK"; private static final String ASK_RESPONSE = "ASK";
private static final String MOVED_RESPONSE = "MOVED"; private static final String MOVED_RESPONSE = "MOVED";
private static final String CLUSTERDOWN_RESPONSE = "CLUSTERDOWN"; private static final String CLUSTERDOWN_RESPONSE = "CLUSTERDOWN";
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 6379; public static final int DEFAULT_PORT = 6379;
public static final int DEFAULT_SENTINEL_PORT = 26379; public static final int DEFAULT_SENTINEL_PORT = 26379;
public static final int DEFAULT_TIMEOUT = 2000; public static final int DEFAULT_TIMEOUT = 2000;