Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GH-2: Allow stringified expiry

  • Loading branch information...
commit 198bcd9a0a590e233933b54340e6aa08b1c1b6e3 1 parent a38f055
@mnunberg mnunberg authored
Showing with 34 additions and 5 deletions.
  1. +23 −1 lib/Couchbase/Test/ClientSync.pm
  2. +11 −4 xs/Client.xs
View
24 lib/Couchbase/Test/ClientSync.pm
@@ -274,4 +274,26 @@ sub T07_stats :Test(no_plan) {
}
}
-1;
+sub T08_expiry :Test(no_plan) {
+ my $self = shift;
+ my $o = $self->cbo;
+ $self->set_ok(
+ "Setting with numeric expiry",
+ "key", "value", 1);
+
+ $self->set_ok(
+ "Setting with stringified expiry",
+ "key", "value", "1");
+
+
+ eval {
+ $o->set("key", "Value", "bad-expiry");
+ };
+ ok($@, "Got error for invalid expiry");
+
+ sleep(1.5);
+ my $rv = $o->get("key");
+ is($rv->errnum, COUCHBASE_KEY_ENOENT, "key has expired");
+}
+
+1;
View
15 xs/Client.xs
@@ -242,11 +242,18 @@ static SV *PLCB_get_common(SV *self, SV *key, int exp_offset)
if(items == (exp_idx - 1)) { \
exp_var = 0; \
} else if(items == exp_idx) { \
- if(!SvIOK(ST(exp_idx-1))) { \
- sv_dump(ST(exp_idx-1)); \
- die("Expected numeric argument"); \
+ SV *_expsv = ST(exp_idx-1); \
+ UV _exp_real; \
+ if (SvIOK(_expsv)) { \
+ exp_var = SvUV(_expsv); \
+ } else if (SvPOK(_expsv)) { \
+ if (!grok_number(SvPVX(_expsv), SvCUR(_expsv), &_exp_real)) { \
+ die("Can't convert expiry string to int"); \
+ } \
+ exp_var = _exp_real; \
+ } else { \
+ die("Expiry is neither numeric nor a string"); \
} \
- exp_var = SvIV(ST((exp_idx-1))); \
} else { \
die(diemsg); \
}
Please sign in to comment.
Something went wrong with that request. Please try again.