add JedisDataException and JedisConnectionException
This commit is contained in:
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
import redis.clients.util.JedisByteHashMap;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import static redis.clients.jedis.Protocol.Keyword.UNSUBSCRIBE;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public abstract class BinaryJedisPubSub {
|
||||
private int subscribedChannels = 0;
|
||||
private Client client;
|
||||
|
||||
@@ -3,11 +3,12 @@ package redis.clients.jedis;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.Protocol.Command;
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
import redis.clients.util.RedisInputStream;
|
||||
import redis.clients.util.RedisOutputStream;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
@@ -60,26 +61,14 @@ public class Connection {
|
||||
}
|
||||
|
||||
protected Connection sendCommand(final Command cmd, final byte[]... args) {
|
||||
try {
|
||||
connect();
|
||||
} catch (UnknownHostException e) {
|
||||
throw new JedisException("Could not connect to redis-server", e);
|
||||
} catch (IOException e) {
|
||||
throw new JedisException("Could not connect to redis-server", e);
|
||||
}
|
||||
connect();
|
||||
protocol.sendCommand(outputStream, cmd, args);
|
||||
pipelinedCommands++;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected Connection sendCommand(final Command cmd) {
|
||||
try {
|
||||
connect();
|
||||
} catch (UnknownHostException e) {
|
||||
throw new JedisException("Could not connect to redis-server", e);
|
||||
} catch (IOException e) {
|
||||
throw new JedisException("Could not connect to redis-server", e);
|
||||
}
|
||||
connect();
|
||||
protocol.sendCommand(outputStream, cmd, new byte[0][]);
|
||||
pipelinedCommands++;
|
||||
return this;
|
||||
@@ -110,12 +99,16 @@ public class Connection {
|
||||
public Connection() {
|
||||
}
|
||||
|
||||
public void connect() throws UnknownHostException, IOException {
|
||||
public void connect() {
|
||||
if (!isConnected()) {
|
||||
socket = new Socket(host, port);
|
||||
socket.setSoTimeout(timeout);
|
||||
outputStream = new RedisOutputStream(socket.getOutputStream());
|
||||
inputStream = new RedisInputStream(socket.getInputStream());
|
||||
try {
|
||||
socket = new Socket(host, port);
|
||||
socket.setSoTimeout(timeout);
|
||||
outputStream = new RedisOutputStream(socket.getOutputStream());
|
||||
inputStream = new RedisInputStream(socket.getInputStream());
|
||||
} catch (IOException ex) {
|
||||
throw new JedisConnectionException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,7 +121,7 @@ public class Connection {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
throw new JedisException(ex);
|
||||
throw new JedisConnectionException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@@ -12,6 +10,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import redis.clients.jedis.BinaryClient.LIST_POSITION;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
|
||||
public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
public Jedis(final String host) {
|
||||
@@ -1647,19 +1646,13 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
|
||||
private void runChecks() {
|
||||
if (client.isInMulti()) {
|
||||
throw new JedisException(
|
||||
throw new JedisDataException(
|
||||
"Cannot use Jedis when in Multi. Please use JedisTransaction instead.");
|
||||
}
|
||||
try {
|
||||
this.connect();
|
||||
} catch (UnknownHostException e) {
|
||||
throw new JedisException(e);
|
||||
} catch (IOException e) {
|
||||
throw new JedisException(e);
|
||||
}
|
||||
this.connect();
|
||||
}
|
||||
|
||||
public void connect() throws UnknownHostException, IOException {
|
||||
public void connect() {
|
||||
if (!client.isConnected()) {
|
||||
client.connect();
|
||||
if (this.password != null) {
|
||||
@@ -1668,7 +1661,7 @@ public class Jedis extends BinaryJedis implements JedisCommands {
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() throws IOException {
|
||||
public void disconnect() {
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class JedisException extends RuntimeException {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2946266495682282677L;
|
||||
|
||||
public JedisException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JedisException(IOException e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public JedisException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import static redis.clients.jedis.Protocol.Keyword.UNSUBSCRIBE;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public abstract class JedisPubSub {
|
||||
|
||||
@@ -4,6 +4,8 @@ import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisConnectionException;
|
||||
import redis.clients.jedis.exceptions.JedisDataException;
|
||||
import redis.clients.util.RedisInputStream;
|
||||
import redis.clients.util.RedisOutputStream;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
@@ -44,13 +46,13 @@ public final class Protocol {
|
||||
}
|
||||
os.flush();
|
||||
} catch (IOException e) {
|
||||
throw new JedisException(e);
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void processError(final RedisInputStream is) {
|
||||
String message = is.readLine();
|
||||
throw new JedisException(message);
|
||||
throw new JedisDataException(message);
|
||||
}
|
||||
|
||||
private Object process(final RedisInputStream is) {
|
||||
@@ -67,10 +69,10 @@ public final class Protocol {
|
||||
} else if (b == PLUS_BYTE) {
|
||||
return processStatusCodeReply(is);
|
||||
} else {
|
||||
throw new JedisException("Unknown reply: " + (char) b);
|
||||
throw new JedisConnectionException("Unknown reply: " + (char) b);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new JedisException(e);
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -94,7 +96,7 @@ public final class Protocol {
|
||||
is.readByte();
|
||||
is.readByte();
|
||||
} catch (IOException e) {
|
||||
throw new JedisException(e);
|
||||
throw new JedisConnectionException(e);
|
||||
}
|
||||
|
||||
return read;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -28,8 +27,7 @@ public class ShardedJedis extends BinaryShardedJedis implements JedisCommands {
|
||||
super(shards, algo, keyTagPattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect() throws IOException {
|
||||
public void disconnect() {
|
||||
for (Jedis jedis : getAllShards()) {
|
||||
jedis.quit();
|
||||
jedis.disconnect();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import redis.clients.jedis.exceptions.JedisException;
|
||||
|
||||
public abstract class TransactionBlock extends Transaction {
|
||||
public TransactionBlock(Client client) {
|
||||
super(client);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
public class JedisConnectionException extends JedisException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
public JedisConnectionException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JedisConnectionException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public JedisConnectionException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
public class JedisDataException extends JedisException {
|
||||
private static final long serialVersionUID = 3878126572474819403L;
|
||||
|
||||
public JedisDataException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JedisDataException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public JedisDataException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package redis.clients.jedis.exceptions;
|
||||
|
||||
|
||||
public class JedisException extends RuntimeException {
|
||||
private static final long serialVersionUID = -2946266495682282677L;
|
||||
|
||||
public JedisException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public JedisException(Throwable e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
public JedisException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user