Permalink
Browse files

retry for increment/decrement

  • Loading branch information...
1 parent 4b93673 commit 14b2027104fc455350c8f541264e54fc2a652e9f @flyerhzm flyerhzm committed Aug 22, 2012
View
@@ -261,6 +261,14 @@
@memcached.set "key", "value"
lambda { @timeout_memcached.get "key" }.should raise_error(Memcached::ATimeoutOccurred)
end
+
+ it "should increment timeout" do
+ lambda { @timeout_memcached.increment "intkey" }.should raise_error(Memcached::ATimeoutOccurred)
+ end
+
+ it "should decrement timeout" do
+ lambda { @timeout_memcached.decrement "intkey" }.should raise_error(Memcached::ATimeoutOccurred)
+ end
end
end
end
@@ -269,8 +269,19 @@ public IRubyObject incr(ThreadContext context, IRubyObject[] args) {
String key = getFullKey(args[0].toString());
int by = getIncrDecrBy(args);
int expiry = getExpiry(args);
- long result = client.incr(key, by, 1, expiry);
- return ruby.newFixnum(result);
+ int retry = 0;
+ while (true) {
+ try {
+ long result = client.incr(key, by, 1, expiry);
+ return ruby.newFixnum(result);
+ } catch (OperationTimeoutException e) {
+ if (retry == exceptionRetryLimit) {
+ throw Error.newATimeoutOccurred(ruby, e.getLocalizedMessage());
+ }
+ retry++;
+ continue;
+ }
+ }
}
@JRubyMethod(name = { "decrement", "decr" }, required = 1, optional = 2)
@@ -279,8 +290,19 @@ public IRubyObject decr(ThreadContext context, IRubyObject[] args) {
String key = getFullKey(args[0].toString());
int by = getIncrDecrBy(args);
int expiry = getExpiry(args);
- long result = client.decr(key, by, 0, expiry);
- return ruby.newFixnum(result);
+ int retry = 0;
+ while (true) {
+ try {
+ long result = client.decr(key, by, 0, expiry);
+ return ruby.newFixnum(result);
+ } catch (OperationTimeoutException e) {
+ if (retry == exceptionRetryLimit) {
+ throw Error.newATimeoutOccurred(ruby, e.getLocalizedMessage());
+ }
+ retry++;
+ continue;
+ }
+ }
}
@JRubyMethod(name = "delete")
Binary file not shown.

0 comments on commit 14b2027

Please sign in to comment.