PHP Класс yii\redis\Connection

By default it assumes there is a redis server running on localhost at port 6379 and uses the database number 0. It is possible to connect to a redis server using [[hostname]] and [[port]] or using a [[unixSocket]]. It also supports the AUTH command of redis. When the server needs authentication, you can set the [[password]] property to authenticate with the server after connect. The execution of redis commands is possible with via Connection::executeCommand.
С версии: 2.0
Автор: Carsten Brandt ([email protected])
Наследование: extends yii\base\Component
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$connectionTimeout timeout to use for connection to redis. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout")
$dataTimeout timeout to use for redis socket when reading and writing data. If not set the php default value will be used.
$database the redis database to use. This is an integer value starting from 0. Defaults to 0. Since version 2.0.6 you can disable the SELECT command sent after connection by setting this property to null.
$hostname the hostname or ip address to use for connecting to the redis server. Defaults to 'localhost'. If [[unixSocket]] is specified, hostname and port will be ignored.
$password the password for establishing DB connection. Defaults to null meaning no AUTH command is send. See http://redis.io/commands/auth
$port the port to use for connecting to the redis server. Default port is 6379. If [[unixSocket]] is specified, hostname and port will be ignored.
$redisCommands List of available redis commands http://redis.io/commands
$socketClientFlags Bitmask field which may be set to any combination of connection flags passed to stream_socket_client(). Currently the select of connection flags is limited to STREAM_CLIENT_CONNECT (default), STREAM_CLIENT_ASYNC_CONNECT and STREAM_CLIENT_PERSISTENT.
$unixSocket the unix socket path (e.g. /var/run/redis/redis.sock) to use for connecting to the redis server. This can be used instead of [[hostname]] and [[port]] to connect to the server using a unix socket. If a unix socket path is specified, [[hostname]] and [[port]] will be ignored.

Открытые методы

Метод Описание
__call ( string $name, array $params ) : mixed Allows issuing all supported commands via magic methods.
__sleep ( ) : array Closes the connection when this component is being serialized.
close ( ) Closes the currently active DB connection.
executeCommand ( string $name, array $params = [] ) : array | boolean | null | string Executes a redis command.
getDriverName ( ) : string Returns the name of the DB driver for the current [[dsn]].
getIsActive ( ) : boolean Returns a value indicating whether the DB connection is established.
getLuaScriptBuilder ( ) : yii\redis\LuaScriptBuilder
open ( ) Establishes a DB connection.

Защищенные методы

Метод Описание
initConnection ( ) Initializes the DB connection.

Приватные методы

Метод Описание
parseResponse ( string $command ) : mixed

Описание методов

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

php $redis->hmset(['test_collection', 'key1', 'val1', 'key2', 'val2'])
public __call ( string $name, array $params ) : mixed
$name string name of the missing method to execute
$params array method call arguments
Результат mixed

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

Closes the connection when this component is being serialized.
public __sleep ( ) : array
Результат array

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

It does nothing if the connection is already closed.
public close ( )

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.

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

Returns the name of the DB driver for the current [[dsn]].
public getDriverName ( ) : string
Результат string name of the DB driver

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

Returns a value indicating whether the DB connection is established.
public getIsActive ( ) : boolean
Результат boolean whether the DB connection is established

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

public getLuaScriptBuilder ( ) : yii\redis\LuaScriptBuilder
Результат yii\redis\LuaScriptBuilder

initConnection() защищенный Метод

This method is invoked right after the DB connection is established. The default implementation triggers an [[EVENT_AFTER_OPEN]] event.
protected initConnection ( )

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

It does nothing if a DB connection has already been established.
public open ( )

Описание свойств

$connectionTimeout публичное свойство

timeout to use for connection to redis. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout")
public $connectionTimeout

$dataTimeout публичное свойство

timeout to use for redis socket when reading and writing data. If not set the php default value will be used.
public $dataTimeout

$database публичное свойство

the redis database to use. This is an integer value starting from 0. Defaults to 0. Since version 2.0.6 you can disable the SELECT command sent after connection by setting this property to null.
public $database

$hostname публичное свойство

the hostname or ip address to use for connecting to the redis server. Defaults to 'localhost'. If [[unixSocket]] is specified, hostname and port will be ignored.
public $hostname

$password публичное свойство

the password for establishing DB connection. Defaults to null meaning no AUTH command is send. See http://redis.io/commands/auth
public $password

$port публичное свойство

the port to use for connecting to the redis server. Default port is 6379. If [[unixSocket]] is specified, hostname and port will be ignored.
public $port

$redisCommands публичное свойство

List of available redis commands http://redis.io/commands
public $redisCommands

$socketClientFlags публичное свойство

Bitmask field which may be set to any combination of connection flags passed to stream_socket_client(). Currently the select of connection flags is limited to STREAM_CLIENT_CONNECT (default), STREAM_CLIENT_ASYNC_CONNECT and STREAM_CLIENT_PERSISTENT.
См. также: http://php.net/manual/en/function.stream-socket-client.php
С версии: 2.0.5
public $socketClientFlags

$unixSocket публичное свойство

the unix socket path (e.g. /var/run/redis/redis.sock) to use for connecting to the redis server. This can be used instead of [[hostname]] and [[port]] to connect to the server using a unix socket. If a unix socket path is specified, [[hostname]] and [[port]] will be ignored.
С версии: 2.0.1
public $unixSocket