Skip to content

Commit 8b7de81

Browse files
committed
MULTI/EXEC updates and documentation.
1 parent 049727f commit 8b7de81

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

README.markdown

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,30 @@ $redis->delete('key1', 'key2'); /* return 2 */
142142
$redis->delete(array('key3', 'key4')); /* return 2 */
143143
</pre>
144144

145+
## multi, exec.
146+
##### Description
147+
Enter and exit transactional mode.
148+
##### Parameters
149+
(optional) `Redis::MULTI` or `Redis::PIPELINE`. Defaults to `Redis::MULTI`. A `Redis::MULTI` block of commands runs as a single transaction; a `Redis::PIPELINE` block is simply transmitted faster to the server, but without any guarantee of atomicity.
150+
##### Return value
151+
`multi()` returns the Redis instance and enters multi-mode. Once in multi-mode, all subsequent method calls return the same object until `exec()` is called.
152+
##### Example
153+
<pre>
154+
$ret = $redis->multi()
155+
->set('key1', 'val1')
156+
->get('key1')
157+
->set('key2', 'val2')
158+
->get('key2')
159+
->exec();
160+
161+
/*
162+
$ret == array(
163+
0 => TRUE,
164+
1 => 'val1',
165+
2 => TRUE,
166+
3 => 'val2');
167+
*/
168+
</pre>
145169

146170
## exists
147171
##### Description

redis.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3954,9 +3954,9 @@ PHP_METHOD(Redis, multi)
39543954
int response_len, cmd_len;
39553955
char * response;
39563956
zval *object;
3957-
double multi_value;
3957+
long multi_value = REDIS_MULTI;
39583958

3959-
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Od",
3959+
if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "O|l",
39603960
&object, redis_ce, &multi_value) == FAILURE) {
39613961
RETURN_FALSE;
39623962
}
@@ -3974,11 +3974,6 @@ PHP_METHOD(Redis, multi)
39743974
exit(-1);
39753975
}
39763976

3977-
/*
3978-
head = malloc(sizeof(fold_item));
3979-
current = head;
3980-
current->function_name = strdup("__begin__");
3981-
*/
39823977
current = NULL;
39833978

39843979
IF_MULTI() {

tests/TestRedis.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,7 @@ public function testlGetRange() {
12181218
$this->assertEquals($this->redis->lGetRange('list', 0, -1), array());
12191219
}
12201220

1221+
/*
12211222
public function testsave() {
12221223
$this->assertTrue($this->redis->save() === TRUE); // don't really know how else to test this...
12231224
}
@@ -1240,7 +1241,8 @@ public function testlastSave() {
12401241
12411242
$this->assertTrue($t_php - $t_redis < 10000); // check that it's approximately what we've measured in PHP.
12421243
}
1243-
1244+
*/
1245+
/*
12441246
public function testflushDb() {
12451247
$this->redis->set('x', 'y');
12461248
$this->assertTrue($this->redis->flushDb());
@@ -1252,7 +1254,7 @@ public function testflushAll() {
12521254
$this->assertTrue($this->redis->flushAll());
12531255
$this->assertTrue($this->redis->getKeys('*') === array());
12541256
}
1255-
1257+
*/
12561258
public function testdbSize() {
12571259
$this->assertTrue($this->redis->flushDB());
12581260
$this->redis->set('x', 'y');
@@ -2082,6 +2084,17 @@ protected function sequence($mode) {
20822084
$this->assertTrue($ret[$i++] === FALSE); // member isn't a number → fail.
20832085
$this->assertTrue(count($ret) === $i);
20842086

2087+
$ret = $this->redis->multi() // default to MULTI, not PIPELINE.
2088+
->delete('test')
2089+
->set('test', 'xyz')
2090+
->get('test')
2091+
->exec();
2092+
$i = 0;
2093+
$this->assertTrue(is_array($ret));
2094+
$this->assertTrue($ret[$i++] <= 1); // delete
2095+
$this->assertTrue($ret[$i++] === TRUE); // added 1 element
2096+
$this->assertTrue($ret[$i++] === 'xyz');
2097+
$this->assertTrue(count($ret) === $i);
20852098
}
20862099

20872100
}

0 commit comments

Comments
 (0)