public function testItExecutesACommand()
 {
     $command = "command";
     $keys = array('key1', 'key2');
     $keyCount = 2;
     $args = array('arg1', 'arg2');
     $this->connectionMock->expects($this->at(0))->method('__call')->with($this->equalTo('eval'), $this->equalTo(array($command, $keyCount, 'key1', 'key2', 'arg1', 'arg2')))->will($this->returnValue("test response"));
     $commandMock = $this->getMock('Phresque\\Redis\\Commands\\CommandInterface');
     $commandMock->expects($this->at(1))->method('getCommand')->will($this->returnValue($command));
     $commandMock->expects($this->at(0))->method('getKeys')->will($this->returnValue($keys));
     $commandMock->expects($this->at(2))->method('getArguments')->will($this->returnValue($args));
     $commandMock->expects($this->at(3))->method('formatResponse')->with($this->equalTo("test response"))->will($this->returnValue("test response formatted"));
     $response = $this->commandExecutor->execute($commandMock);
     $this->assertEquals("test response formatted", $response);
 }
Beispiel #2
0
 public function search($page = 0, $limit = 200)
 {
     $end = $this->timeEnd ? $this->timeEnd->getTimestamp() : Time::microtime() + 1;
     $start = $this->timeStart ? $this->timeStart->getTimestamp() : 0;
     $args = array($start, $end, $page * $limit, $limit);
     $keys = $this->buildSearchKeys();
     if (($keysCount = count($keys)) > 1) {
         $args[] = $keysCount;
         $keysString = "ARGV[5]";
         foreach ($keys as $i => $k) {
             $keysString .= " ,KEYS[" . ($i + 2) . "]";
         }
         $command = "redis.call('zinterstore', KEYS[1], {$keysString}, 'AGGREGATE', 'MAX')" . PHP_EOL;
         array_unshift($keys, 'searchtmp:' . uniqid(getmypid() . ':', true));
     } else {
         $command = "";
         count($keys) or $keys[0] = 'index:job:all';
     }
     // zREVrangebyscore so ARG[2] ARG[1] are reversed
     $command .= "local result = redis.call('zrevrangebyscore', KEYS[1], ARGV[2], ARGV[1], 'LIMIT', ARGV[3], ARGV[4])" . PHP_EOL;
     $command .= "local count = redis.call('zcount', KEYS[1], ARGV[1], ARGV[2])" . PHP_EOL;
     if ($keysCount > 1) {
         $command .= "redis.call('del', KEYS[1])" . PHP_EOL;
     }
     $command .= 'return {count, result}';
     list($count, $list) = $this->commandExecutor->execute(new Phresque\Redis\Commands\DynamicCommand($command, $keys, $args));
     $jobs = array();
     foreach ($list as $jobID) {
         $jobs[] = $this->commandExecutor->execute(new Phresque\Redis\Commands\GetJob($jobID));
     }
     return $this->withCount ? array($jobs, $count) : $jobs;
 }
Beispiel #3
0
 public function setValue($key, $value, $overwrite = true)
 {
     $this->validateKey($key);
     $this->commandExecutor->execute(new GlobalConfig($key, $value, $overwrite));
     return $this;
 }
Beispiel #4
0
 public function removeJobById($jobId)
 {
     if (!$this->commandExecutor->execute(new RemoveJobById($jobId))) {
         throw new JobNotFoundException("Job [ {$jobId} ] could not be deleted because it was not found in any queue");
     }
 }