mirror of
https://github.com/predis/predis.git
synced 2026-08-24 01:39:36 +00:00
update sort command to be a write operation
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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.'
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user