Exemple #1
0
 /**
  * {@inheritdoc}
  */
 public function add(SingleConnectionInterface $connection)
 {
     $parameters = $connection->getParameters();
     if (isset($parameters->alias)) {
         $this->pool[$parameters->alias] = $connection;
     } else {
         $this->pool[] = $connection;
     }
     $weight = isset($parameters->weight) ? $parameters->weight : null;
     $this->distributor->add($connection, $weight);
 }
 /**
  * @param AccessTokenInterface|string $token
  * @return bool
  */
 function delete($token)
 {
     $deleted = false;
     if (!$token instanceof AccessTokenInterface) {
         $token = $this->find($token);
     }
     if ($token) {
         $deleted = $this->redis->del($this->key($token->getId()));
         $deleted = $deleted > 0;
     }
     return $deleted;
 }
 /**
  * @param AuthorizationCodeInterface|string $code
  * @return bool
  */
 function delete($code)
 {
     $deleted = false;
     if (!$code instanceof AuthorizationCodeInterface) {
         $code = $this->find($code);
     }
     if ($code) {
         $key = $this->key($code->getId());
         $deleted = $this->redis->del($key);
         $deleted = $deleted > 0;
     }
     return $deleted;
 }
 /**
  * {@inheritdoc}
  */
 public function remove(SingleConnectionInterface $connection)
 {
     if ($connection->getParameters()->alias === 'master') {
         $this->master = null;
         $this->reset();
         return true;
     } else {
         if (($id = array_search($connection, $this->slaves, true)) !== false) {
             unset($this->slaves[$id]);
             $this->reset();
             return true;
         }
     }
     return false;
 }
 /**
  * {@inheritdoc}
  */
 public function executeCommand(CommandInterface $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;
 }
 /**
  * Prepares a connection object after its initialization.
  *
  * @param SingleConnectionInterface $connection Instance of a connection object.
  */
 protected function prepareConnection(SingleConnectionInterface $connection)
 {
     if (isset($this->profile)) {
         $parameters = $connection->getParameters();
         if (isset($parameters->password)) {
             $command = $this->profile->createCommand('auth', array($parameters->password));
             $connection->pushInitCommand($command);
         }
         if (isset($parameters->database)) {
             $command = $this->profile->createCommand('select', array($parameters->database));
             $connection->pushInitCommand($command);
         }
     }
 }