Skip to content

Commit d0d0034

Browse files
committed
Make sure publish() can be called in a pipeline.
This will also make it possible to use publish() in a MULTI/EXEC context. Fixes GitHub issue phpredis#104.
1 parent 78f0abf commit d0d0034

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

redis.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4840,12 +4840,11 @@ PHP_METHOD(Redis, publish)
48404840
cmd_len = redis_cmd_format_static(&cmd, "PUBLISH", "ss", key, key_len, val, val_len);
48414841
if(key_free) efree(key);
48424842

4843-
if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) {
4844-
efree(cmd);
4845-
RETURN_FALSE;
4843+
REDIS_PROCESS_REQUEST(redis_sock, cmd, cmd_len);
4844+
IF_ATOMIC() {
4845+
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
48464846
}
4847-
efree(cmd);
4848-
redis_long_response(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, NULL, NULL);
4847+
REDIS_PROCESS_RESPONSE(redis_long_response);
48494848
}
48504849

48514850
/*

tests/TestRedis.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ public function testPing()
5555
}
5656
}
5757

58+
public function testPipelinePublish() {
59+
60+
$ret = $this->redis->pipeline()
61+
->publish('chan', 'msg')
62+
->exec();
63+
64+
$this->assertTrue(is_array($ret) && count($ret) === 1 && $ret[0] >= 0);
65+
}
66+
5867
public function testBitsets() {
5968

6069
$this->redis->delete('key');

0 commit comments

Comments
 (0)