Implement Closeable for Jedis, BinaryJedis etc.
This allows a Jedis object to participate in try-with-resources when using Java 7+. This change is fully backwards compatible to Java 6 and previous releases of the Jedis client.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package redis.clients.jedis;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
@@ -15,7 +16,7 @@ import redis.clients.util.RedisInputStream;
|
||||
import redis.clients.util.RedisOutputStream;
|
||||
import redis.clients.util.SafeEncoder;
|
||||
|
||||
public class Connection {
|
||||
public class Connection implements Closeable {
|
||||
private String host;
|
||||
private int port = Protocol.DEFAULT_PORT;
|
||||
private Socket socket;
|
||||
@@ -143,6 +144,11 @@ public class Connection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
disconnect();
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
if (isConnected()) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user