Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions redis_cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -3484,6 +3484,9 @@ PHP_METHOD(RedisCluster, rawcommand) {
/* Free argument array */
efree(z_args);

/* We can't know if a raw command writes, so always send it to the master */
c->readonly = 0;

/* Direct the command */
const REDIS_REPLY_TYPE rtype = cluster_is_atomic(c) ? TYPE_EOF : TYPE_LINE;
if (cluster_send_slot_cmd(c, cmd->slot, cmd, rtype) < 0) {
Expand Down
27 changes: 27 additions & 0 deletions tests/RedisClusterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,33 @@ public function testDirectedFlushUsesMaster() {
);
}

/* Regression test for GH #3017 */
public function testDirectedRawCommandUsesMaster() {
$masters = $this->redis->_masters();
$this->assertArrayKey($masters, 0, 'is_array');
$master = $masters[0];

$this->assertTrue(
$this->redis->setOption(
RedisCluster::OPT_SLAVE_FAILOVER,
RedisCluster::FAILOVER_DISTRIBUTE_SLAVES
)
);

/* A read must not leave the next raw command readonly */
$this->redis->get('foo');

/* Should succeed being sent to the primary */
$this->assertTrue($this->redis->rawCommand($master, 'FLUSHDB'));

$this->assertTrue(
$this->redis->setOption(
RedisCluster::OPT_SLAVE_FAILOVER,
RedisCluster::FAILOVER_NONE
)
);
}

/* Regression test for setting TCP_KEEPALIVE on the hostless cluster flags socket */
public function testSetTcpKeepaliveOption() {
$this->assertTrue(
Expand Down
Loading