Skip to content

Commit

Permalink
Merge pull request redis#199 from sehugg/jedis
Browse files Browse the repository at this point in the history
---

The subscribe and psubscribe operations call setTimeoutInfinite() since they never return on their own. If the Redis server goes away without closing the connection, the connection can hang indefinitely. Turning on keep-alive will allow the connection to eventually timeout and attempt reconnection.

Note that keepalive must also be enabled on your server, see the Linux HOWTOs on how to do this.
  • Loading branch information
ewhauser committed Sep 13, 2011
2 parents a9ef10b + 33ceb6d commit dba5e2c
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/redis/clients/jedis/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void setTimeout(final int timeout) {

public void setTimeoutInfinite() {
try {
socket.setKeepAlive(true);
socket.setSoTimeout(0);
} catch (SocketException ex) {
throw new JedisException(ex);
Expand All @@ -47,6 +48,7 @@ public void setTimeoutInfinite() {
public void rollbackTimeout() {
try {
socket.setSoTimeout(timeout);
socket.setKeepAlive(false);
} catch (SocketException ex) {
throw new JedisException(ex);
}
Expand Down

0 comments on commit dba5e2c

Please sign in to comment.