Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

provide a reset() method to read all remaining data #213

Open
wants to merge 1 commit into from

2 participants

@raszi

It would be useful to have a reset() method in Jedis client.

It could be called before returning a shared Jedis client to the pool, or borrowing it again.

@raszi

All tests passed.

@xetorthio
Owner

what would be the use case of this? can you provide an example?

@raszi

Jedis client has an inner state, which cannot be altered from outside. So if the client sent some bytes to the server and a timeout occurred, then it is impossible to reset this client to a normal state without this method.

@xetorthio
Owner

Ok. In that case you'll get a JedisConnectionException. Whenever you get this excption you are supposed to returnBrokenResource instead of returnResource.
This way this resource can be deleted and a new one is created.
Do you still think this is necessary?

@raszi

But the timeouted client could be restored with this reset() method, and creating a new object with connecting and selecting database could take more resource than a simple reset.

If you don't want to use reset() and return just a broken resource it depends on you, but this would take no harm and provides a better API, because the inner state could be reset.

@xetorthio
Owner
@raszi

sending requests on a closed connection always cause exceptions don't they?

so reset() won't differ from any other command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 26, 2011
  1. @raszi
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 0 deletions.
  1. +9 −0 src/main/java/redis/clients/jedis/Jedis.java
View
9 src/main/java/redis/clients/jedis/Jedis.java
@@ -34,6 +34,15 @@ public String ping() {
}
/**
+ * Resets the client.
+ * <p>
+ * Reads all remaining responses from the input.
+ */
+ public void reset() {
+ client.getAll();
+ }
+
+ /**
* Set the string value as value of the key. The string can't be longer than
* 1073741824 bytes (1 GB).
* <p>
Something went wrong with that request. Please try again.