/** * @group disconnected */ public function testMovedResponseWithConnectionNotInPool() { $movedResponse = new ResponseError('MOVED 1970 127.0.0.1:6381'); $command = ServerProfile::getDefault()->createCommand('get', array('node:1001')); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); $connection1->expects($this->once())->method('executeCommand')->with($command)->will($this->returnValue($movedResponse)); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); $connection2->expects($this->never())->method('executeCommand'); $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381'); $connection3->expects($this->exactly(2))->method('executeCommand')->with($command)->will($this->onConsecutiveCalls('foobar', 'foobar')); $factory = $this->getMock('Predis\\Connection\\ConnectionFactory'); $factory->expects($this->once())->method('create')->with(array('host' => '127.0.0.1', 'port' => '6381'))->will($this->returnValue($connection3)); $cluster = new RedisCluster($factory); $cluster->add($connection1); $cluster->add($connection2); $this->assertSame('foobar', $cluster->executeCommand($command)); $this->assertSame('foobar', $cluster->executeCommand($command)); $this->assertSame(3, count($cluster)); }
/** * @group disconnected */ public function testAskSlotsMapToRedisClusterOnMovedResponseByDefault() { $cmdGET = RawCommand::create('GET', 'node:1001'); $rspMOVED = new ResponseError('MOVED 1970 127.0.0.1:6380'); $rspSlotsArray = array(array(0, 8191, array('127.0.0.1', 6379)), array(8192, 16383, array('127.0.0.1', 6380))); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); $connection1->expects($this->once())->method('executeCommand')->with($cmdGET)->will($this->returnValue($rspMOVED)); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); $connection2->expects($this->at(0))->method('executeCommand')->with($this->isRedisCommand('CLUSTER', array('SLOTS')))->will($this->returnValue($rspSlotsArray)); $connection2->expects($this->at(2))->method('executeCommand')->with($cmdGET)->will($this->returnValue('foobar')); $factory = $this->getMock('Predis\\Connection\\ConnectionFactory'); $factory->expects($this->once())->method('create')->with(array('host' => '127.0.0.1', 'port' => '6380'))->will($this->returnValue($connection2)); $cluster = new RedisCluster($factory); $cluster->add($connection1); $this->assertSame('foobar', $cluster->executeCommand($cmdGET)); $this->assertSame(2, count($cluster)); }