Exemple #1
0
 /**
  * @return array
  * @throws \Exception
  */
 public function writeToRedis()
 {
     if (!isset($this->pipeLine)) {
         throw new \Exception('No Redis Pipeline Set');
     }
     $results = $this->pipeLine->execute();
     $this->disconnectFromServer();
     return $results;
 }
 /**
  * @group disconnected
  */
 public function testExecuteWithCallableArgumentHandlesExceptions()
 {
     $exception = null;
     $connection = $this->getMock('Predis\\Connection\\SingleConnectionInterface');
     $connection->expects($this->never())->method('writeCommand');
     $connection->expects($this->never())->method('readResponse');
     $pipeline = new PipelineContext(new Client($connection));
     $exception = null;
     $replies = null;
     try {
         $replies = $pipeline->execute(function ($pipe) {
             $pipe->echo('one');
             throw new ClientException('TEST');
             $pipe->echo('two');
         });
     } catch (\Exception $exception) {
         // NOOP
     }
     $this->assertInstanceOf('Predis\\ClientException', $exception);
     $this->assertSame('TEST', $exception->getMessage());
     $this->assertNull($replies);
 }
Exemple #3
0
 /**
  * Executes a pipeline context when a callable object is passed.
  *
  * @param array $options Options of the context initialization.
  * @param mixed $callable Optional callable object used to execute the context.
  * @return PipelineContext|array
  */
 private function pipelineExecute(PipelineContext $pipeline, $callable)
 {
     return isset($callable) ? $pipeline->execute($callable) : $pipeline;
 }
Exemple #4
0
 /**
  * Updates the rank of a news item.
  *
  * @param PipelineContext $pipe Pipeline used to batch the update operations.
  * @param array $news Single news item.
  */
 protected function updateNewsRank(PipelineContext $pipe, array &$news)
 {
     $realRank = $this->computeNewsRank($news);
     if (abs($realRank - $news['rank']) > 0.001) {
         $pipe->hmset("news:{$news['id']}", 'rank', $realRank);
         $pipe->zadd('news.top', $realRank, $news['id']);
         $news['rank'] = $realRank;
     }
 }