Skip to content
This repository was archived by the owner on Apr 20, 2022. It is now read-only.

Commit 3520df6

Browse files
committed
PCBC-251: Add missing prefix for incr/decr/unlock
Change-Id: I350d2492f5a5eb196d1474650be138a842348920 Reviewed-on: http://review.couchbase.org/29246 Reviewed-by: Brett Lawson <brett19@gmail.com> Tested-by: Trond Norbye <trond.norbye@gmail.com>
1 parent 325acac commit 3520df6

File tree

6 files changed

+85
-0
lines changed

6 files changed

+85
-0
lines changed

arithmetic.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ void php_couchbase_arithmetic_impl(INTERNAL_FUNCTION_PARAMETERS, char op, int oo
7070
memset(&cookie, 0, sizeof(cookie));
7171
delta = (op == '+') ? offset : -offset;
7272

73+
if (couchbase_res->prefix_key_len) {
74+
klen = spprintf(&key, 0, "%s_%s", couchbase_res->prefix_key, key);
75+
}
76+
7377
memset(&cmd, 0, sizeof(cmd));
7478
cmd.v.v0.key = key;
7579
cmd.v.v0.nkey = klen;
@@ -82,6 +86,10 @@ void php_couchbase_arithmetic_impl(INTERNAL_FUNCTION_PARAMETERS, char op, int oo
8286
retval = lcb_arithmetic(instance, &cookie, 1, commands);
8387
lcb_behavior_set_syncmode(instance, LCB_ASYNCHRONOUS);
8488

89+
if (couchbase_res->prefix_key_len) {
90+
efree(key);
91+
}
92+
8593
if (retval == LCB_SUCCESS) {
8694
retval = cookie.error ;
8795
}

remove.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,17 @@ void php_couchbase_remove_impl(INTERNAL_FUNCTION_PARAMETERS, int oo)
105105
}
106106
}
107107

108+
if (couchbase_res->prefix_key_len) {
109+
klen = spprintf(&key, 0, "%s_%s", couchbase_res->prefix_key, key);
110+
}
111+
108112
retval = do_remove(couchbase_res->handle, key, klen, &cas_v);
109113
couchbase_res->rc = retval;
110114

115+
if (couchbase_res->prefix_key_len) {
116+
efree(key);
117+
}
118+
111119
switch (retval) {
112120
case LCB_SUCCESS:
113121
Z_TYPE_P(return_value) = IS_STRING;

tests/Regression.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,36 @@ class Regression extends CouchbaseTestCommon {
107107
}
108108
$this->assertEquals("", $msg);
109109
}
110+
111+
function testPCBC_251() {
112+
$handle = $this->handle;
113+
couchbase_set_option($handle, Couchbase::OPT_PREFIX_KEY, "PCBC-251");
114+
couchbase_delete($handle, "counter");
115+
couchbase_add($handle, "counter", 2);
116+
$this->assertEquals(1, couchbase_decrement($handle, "counter"));
117+
$this->assertEquals(0, couchbase_decrement($handle, "counter"));
118+
$lock = 0;
119+
$this->assertEquals(0, couchbase_get_and_lock($handle, "counter", $lock, 1));
120+
$this->assertTrue(couchbase_unlock($handle, "counter", $lock));
121+
# decr 0 -> 0
122+
$this->assertEquals(0, couchbase_decrement($handle, "counter"));
123+
couchbase_set_option($handle, Couchbase::OPT_PREFIX_KEY, "");
124+
}
125+
126+
function testPCBC_251_oo() {
127+
$oo = $this->oo;
128+
$oo->setOption(Couchbase::OPT_PREFIX_KEY, "PCBC-251");
129+
$oo->delete("counter");
130+
$oo->add("counter", 2);
131+
$this->assertEquals(1, $oo->decrement("counter"));
132+
$this->assertEquals(0, $oo->decrement("counter"));
133+
$lock = 0;
134+
$this->assertEquals(0, $oo->getAndLock("counter", $lock, 1));
135+
$this->assertTrue($oo->unlock("counter", $lock));
136+
137+
# decr 0 -> 0
138+
$this->assertEquals(0, $oo->decrement("counter"));
139+
$oo->setOption(Couchbase::OPT_PREFIX_KEY, "");
140+
}
141+
110142
}

tests/phpt/Regression/PCBC_251.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Regression - PCBC_251
3+
4+
--SKIPIF--
5+
<?php
6+
include dirname(__FILE__)."/../../cbtestframework/cbtest-phpt-loader.inc";
7+
couchbase_phpt_skipif("Regression", "testPCBC_251");
8+
9+
--FILE--
10+
<?php
11+
include dirname(__FILE__)."/../../cbtestframework/cbtest-phpt-loader.inc";
12+
couchbase_phpt_runtest("Regression", "testPCBC_251");
13+
--EXPECT--
14+
PHP_COUCHBASE_OK
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Regression - PCBC_251_oo
3+
4+
--SKIPIF--
5+
<?php
6+
include dirname(__FILE__)."/../../cbtestframework/cbtest-phpt-loader.inc";
7+
couchbase_phpt_skipif("Regression", "testPCBC_251_oo");
8+
9+
--FILE--
10+
<?php
11+
include dirname(__FILE__)."/../../cbtestframework/cbtest-phpt-loader.inc";
12+
couchbase_phpt_runtest("Regression", "testPCBC_251_oo");
13+
--EXPECT--
14+
PHP_COUCHBASE_OK

unlock.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,18 @@ void php_couchbase_unlock_impl(INTERNAL_FUNCTION_PARAMETERS, int oo)
8585
return;
8686
}
8787

88+
89+
if (couchbase_res->prefix_key_len) {
90+
klen = spprintf(&key, 0, "%s_%s", couchbase_res->prefix_key, key);
91+
}
92+
8893
retval = do_unlock(couchbase_res->handle, key, klen, cas_v);
8994
couchbase_res->rc = retval;
9095

96+
if (couchbase_res->prefix_key_len) {
97+
efree(key);
98+
}
99+
91100
if (retval == LCB_SUCCESS) {
92101
RETVAL_TRUE;
93102
} else {

0 commit comments

Comments
 (0)