From 39ff616e86b57c4eba85da7cef94960a4e692dce Mon Sep 17 00:00:00 2001 From: Mark Fettig Date: Mon, 18 Mar 2019 12:10:26 -0400 Subject: [PATCH] update sort command to be a write operation --- src/Replication/ReplicationStrategy.php | 26 ------------------- .../Aggregate/MasterSlaveReplicationTest.php | 23 ---------------- .../Replication/ReplicationStrategyTest.php | 12 ++++----- 3 files changed, 6 insertions(+), 55 deletions(-) diff --git a/src/Replication/ReplicationStrategy.php b/src/Replication/ReplicationStrategy.php index cd2d0ed5..9a6015d5 100644 --- a/src/Replication/ReplicationStrategy.php +++ b/src/Replication/ReplicationStrategy.php @@ -89,31 +89,6 @@ class ReplicationStrategy return isset($this->disallowed[$command->getId()]); } - /** - * Checks if a SORT command is a readable operation by parsing the arguments - * array of the specified commad instance. - * - * @param CommandInterface $command Command instance. - * - * @return bool - */ - protected function isSortReadOnly(CommandInterface $command) - { - $arguments = $command->getArguments(); - $argc = count($arguments); - - if ($argc > 1) { - for ($i = 1; $i < $argc; ++$i) { - $argument = strtoupper($arguments[$i]); - if ($argument === 'STORE') { - return false; - } - } - } - - return true; - } - /** * Checks if BITFIELD performs a read-only operation by looking for certain * SET and INCRYBY modifiers in the arguments array of the command. @@ -292,7 +267,6 @@ class ReplicationStrategy 'BITPOS' => true, 'TIME' => true, 'PFCOUNT' => true, - 'SORT' => array($this, 'isSortReadOnly'), 'BITFIELD' => array($this, 'isBitfieldReadOnly'), 'GEOHASH' => true, 'GEOPOS' => true, diff --git a/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php b/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php index 0f210b76..4c1249fb 100644 --- a/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php +++ b/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php @@ -541,29 +541,6 @@ class MasterSlaveReplicationTest extends PredisTestCase $replication->executeCommand($cmdEval); } - /** - * @group disconnected - */ - public function testSortTriggersSwitchToMasterConnectionOnStoreModifier() - { - $profile = Profile\Factory::get('dev'); - $cmdSortNormal = $profile->createCommand('sort', array('key')); - $cmdSortStore = $profile->createCommand('sort', array('key', array('store' => 'key:store'))); - - $master = $this->getMockConnection('tcp://host1?alias=master'); - $master->expects($this->once())->method('executeCommand')->with($cmdSortStore); - - $slave1 = $this->getMockConnection('tcp://host2?alias=slave1'); - $slave1->expects($this->once())->method('executeCommand')->with($cmdSortNormal); - - $replication = new MasterSlaveReplication(); - $replication->add($master); - $replication->add($slave1); - - $replication->executeCommand($cmdSortNormal); - $replication->executeCommand($cmdSortStore); - } - /** * @group disconnected */ diff --git a/tests/Predis/Replication/ReplicationStrategyTest.php b/tests/Predis/Replication/ReplicationStrategyTest.php index b1237c17..cb52ab20 100644 --- a/tests/Predis/Replication/ReplicationStrategyTest.php +++ b/tests/Predis/Replication/ReplicationStrategyTest.php @@ -81,15 +81,15 @@ class ReplicationStrategyTest extends PredisTestCase $profile = Profile\Factory::getDevelopment(); $strategy = new ReplicationStrategy(); - $cmdReadSort = $profile->createCommand('SORT', array('key:list')); - $this->assertTrue( - $strategy->isReadOperation($cmdReadSort), - 'SORT is expected to be a read operation.' + $cmdReturnSort = $profile->createCommand('SORT', array('key:list')); + $this->assertFalse( + $strategy->isReadOperation($cmdReturnSort), + 'SORT is expected to be a write operation.' ); - $cmdWriteSort = $profile->createCommand('SORT', array('key:list', array('store' => 'key:stored'))); + $cmdStoreSort = $profile->createCommand('SORT', array('key:list', array('store' => 'key:stored'))); $this->assertFalse( - $strategy->isReadOperation($cmdWriteSort), + $strategy->isReadOperation($cmdStoreSort), 'SORT with STORE is expected to be a write operation.' ); }