Ejemplo n.º 1
0
 /**
  * Proxy function.
  *
  * @param string $name      A command name
  * @param array  $arguments Lit of command arguments
  *
  * @throws \RuntimeException If no Redis instance is defined
  *
  * @return mixed
  */
 private function call($name, array $arguments = array())
 {
     $startTime = microtime(true);
     $result = call_user_func_array("parent::{$name}", $arguments);
     $duration = (microtime(true) - $startTime) * 1000;
     $this->logger->logCommand($this->getCommandString($name, $arguments), $duration, $this->alias, false);
     return $result;
 }
Ejemplo n.º 2
0
 public function testCommandsWithoutLogger()
 {
     $redisLogger = new RedisLogger();
     for ($i = 0; $i < 3; $i++) {
         $redisLogger->logCommand('foo' . $i, ($i + 1) * 10, 'connection', $i % 2 ? 'error message' : false);
     }
     $this->assertEquals(array(), $redisLogger->getCommands());
 }
 /**
  * {@inheritdoc}
  */
 public function executeCommand(ICommand $command)
 {
     if (null === $this->logger) {
         return $this->connection->executeCommand($command);
     }
     $startTime = microtime(true);
     $result = $this->connection->executeCommand($command);
     $duration = (microtime(true) - $startTime) * 1000;
     $error = $result instanceof ResponseError ? (string) $result : false;
     $this->logger->logCommand((string) $command, $duration, $this->getParameters()->alias, $error);
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * {@inheritDoc}
  * Overload somes commands (get, set...) in order to log the result
  */
 public function __call($name, array $arguments)
 {
     $log = true;
     switch (strtolower($name)) {
         case 'connect':
         case 'open':
         case 'pconnect':
         case 'popen':
         case 'close':
         case 'setoption':
         case 'getoption':
         case 'auth':
         case 'select':
             $log = false;
             break;
     }
     $startTime = microtime(true);
     $result = parent::__call($name, $arguments);
     $duration = (microtime(true) - $startTime) * 1000;
     if ($log && null !== $this->logger) {
         $this->logger->logCommand($this->getCommandString($name, $arguments), $duration, $this->alias, false);
     }
     return $result;
 }
 /**
  * {@inheritdoc}
  */
 public function collect(Request $request, Response $response, \Exception $exception = null)
 {
     $this->data = array('commands' => null !== $this->logger ? $this->logger->getCommands() : array());
 }