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:
Henning Schmiedehausen
2014-02-07 13:39:41 -08:00
parent 51a4bf9a56
commit 7449619fca
3 changed files with 20 additions and 2 deletions

View File

@@ -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 {