mirror of
https://github.com/php-win-ext/phpredis.git
synced 2026-03-24 00:52:16 +01:00
@@ -299,9 +299,8 @@ static int cluster_send_readonly(RedisSock *redis_sock) {
|
||||
|
||||
/* Send MULTI to a specific ReidsSock */
|
||||
static int cluster_send_multi(redisCluster *c, short slot) {
|
||||
if (cluster_send_direct(SLOT_SOCK(c,slot), RESP_MULTI_CMD,
|
||||
sizeof(RESP_MULTI_CMD) - 1, TYPE_LINE) == 0)
|
||||
{
|
||||
if (cluster_send_direct(SLOT_SOCK(c,slot), ZEND_STRL(RESP_MULTI_CMD), TYPE_LINE) == 0) {
|
||||
c->flags->txBytes += sizeof(RESP_MULTI_CMD) - 1;
|
||||
c->cmd_sock->mode = MULTI;
|
||||
return 0;
|
||||
}
|
||||
@@ -1513,6 +1512,9 @@ PHP_REDIS_API int cluster_send_slot(redisCluster *c, short slot, char *cmd,
|
||||
/* Point our cluster to this slot and it's socket */
|
||||
c->cmd_slot = slot;
|
||||
c->cmd_sock = SLOT_SOCK(c, slot);
|
||||
if (c->flags->mode != MULTI) {
|
||||
c->flags->txBytes = 0;
|
||||
}
|
||||
|
||||
/* Enable multi mode on this slot if we've been directed to but haven't
|
||||
* send it to this node yet */
|
||||
@@ -1527,6 +1529,7 @@ PHP_REDIS_API int cluster_send_slot(redisCluster *c, short slot, char *cmd,
|
||||
if (cluster_sock_write(c, cmd, cmd_len, 1) == -1) {
|
||||
return -1;
|
||||
}
|
||||
c->flags->txBytes += cmd_len;
|
||||
|
||||
/* Check our response */
|
||||
if (cluster_check_response(c, &c->reply_type) != 0 ||
|
||||
|
||||
@@ -3128,7 +3128,12 @@ redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz)
|
||||
if (redis_check_eof(redis_sock, 0, 0) == 0 &&
|
||||
php_stream_write(redis_sock->stream, cmd, sz) == sz
|
||||
) {
|
||||
return redis_sock->txBytes = sz;
|
||||
if (IS_MULTI(redis_sock)) {
|
||||
redis_sock->txBytes += sz;
|
||||
} else {
|
||||
redis_sock->txBytes = sz;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1712,7 +1712,8 @@ PHP_METHOD(RedisCluster, clearlasterror) {
|
||||
}
|
||||
|
||||
PHP_METHOD(RedisCluster, gettransferredbytes) {
|
||||
CLUSTER_THROW_EXCEPTION("Not implemented", 0);
|
||||
redisCluster *c = GET_CONTEXT();
|
||||
RETURN_LONG(c->flags->txBytes);
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@@ -1833,6 +1834,8 @@ PHP_METHOD(RedisCluster, multi) {
|
||||
/* Flag that we're in MULTI mode */
|
||||
c->flags->mode = MULTI;
|
||||
|
||||
c->flags->txBytes = 0;
|
||||
|
||||
/* Return our object so we can chain MULTI calls */
|
||||
RETVAL_ZVAL(getThis(), 1, 0);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ class Redis_Cluster_Test extends Redis_Test {
|
||||
public function testReset() { return $this->markTestSkipped(); }
|
||||
public function testInvalidAuthArgs() { return $this->markTestSkipped(); }
|
||||
public function testScanErrors() { return $this->markTestSkipped(); }
|
||||
public function testTransferredBytes() { return $this->markTestSkipped(); }
|
||||
|
||||
public function testlMove() { return $this->markTestSkipped(); }
|
||||
public function testlPos() { return $this->marktestSkipped(); }
|
||||
@@ -759,6 +758,15 @@ class Redis_Cluster_Test extends Redis_Test {
|
||||
ini_set('redis.pconnect.pooling_enabled', $prev_value);
|
||||
}
|
||||
|
||||
public function testTransferredBytes() {
|
||||
$this->assertTrue($this->redis->ping(''));
|
||||
$this->assertEquals(strlen("*1\r\n$4\r\nPING\r\n"), $this->redis->getTransferredBytes());
|
||||
$this->assertEquals(['cluster_enabled' => 1], $this->redis->info('', 'cluster'));
|
||||
$this->assertEquals(strlen("*2\r\n$4\r\nINFO\r\n$7\r\ncluster\r\n"), $this->redis->getTransferredBytes());
|
||||
$this->assertEquals([true, true], $this->redis->multi()->ping('')->ping('')->exec());
|
||||
$this->assertEquals(strlen("*1\r\n$5\r\nMULTI\r\n*1\r\n$4\r\nEXEC\r\n") + 2 * strlen("*2\r\n$4\r\nPING\r\n"), $this->redis->getTransferredBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
|
||||
@@ -5757,6 +5757,8 @@ class Redis_Test extends TestSuite
|
||||
$this->assertEquals(strlen("*1\r\n$4\r\nPING\r\n"), $this->redis->getTransferredBytes());
|
||||
$this->assertEquals(['cluster_enabled' => 0], $this->redis->info('cluster'));
|
||||
$this->assertEquals(strlen("*2\r\n$4\r\nINFO\r\n$7\r\ncluster\r\n"), $this->redis->getTransferredBytes());
|
||||
$this->assertEquals([true, true], $this->redis->multi()->ping()->ping()->exec());
|
||||
$this->assertEquals(strlen("*1\r\n$5\r\nMULTI\r\n*1\r\n$4\r\nEXEC\r\n") + 2 * strlen("*2\r\n$4\r\nPING\r\n"), $this->redis->getTransferredBytes());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user