yii\redis\Connection::executeCommand PHP Метод

executeCommand() публичный Метод

For a list of available commands and their parameters see http://redis.io/commands.
public executeCommand ( string $name, array $params = [] ) : array | boolean | null | string
$name string the name of the command
$params array list of parameters for the command
Результат array | boolean | null | string Dependent on the executed command this method will return different data types: - `true` for commands that return "status reply" with the message `'OK'` or `'PONG'`. - `string` for commands that return "status reply" that does not have the message `OK` (since version 2.0.1). - `string` for commands that return "integer reply" as the value is in the range of a signed 64 bit integer. - `string` or `null` for commands that return "bulk reply". - `array` for commands that return "Multi-bulk replies". See [redis protocol description](http://redis.io/topics/protocol) for details on the mentioned reply types.
    public function executeCommand($name, $params = [])
    {
        $this->open();
        array_unshift($params, $name);
        $command = '*' . count($params) . "\r\n";
        foreach ($params as $arg) {
            $command .= '$' . mb_strlen($arg, '8bit') . "\r\n" . $arg . "\r\n";
        }
        \Yii::trace("Executing Redis Command: {$name}", __METHOD__);
        fwrite($this->_socket, $command);
        return $this->parseResponse(implode(' ', $params));
    }

Usage Example

Пример #1
0
 /**
  * @return mixed
  * @throws InvalidConfigException
  */
 public function configGetDatabases()
 {
     try {
         if ($this->_connect instanceof PhpredisConnection) {
             return $this->_connect->executeCommand('CONFIG', ['GET', 'databases'])['databases'];
         } else {
             return $this->_connect->executeCommand('CONFIG', ['GET', 'databases'])[1];
         }
     } catch (\Exception $e) {
         throw new InvalidConfigException('Can`t connect to redis database, please check module and redis-connection settings!!!!');
     }
 }
All Usage Examples Of yii\redis\Connection::executeCommand