PHP Класс Credis_Sentinel

Implements the Sentinel API as mentioned on http://redis.io/topics/sentinel. Sentinel is aware of master and slave nodes in a cluster and returns instances of Credis_Client accordingly. The complexity of read/write splitting can also be abstract by calling the createCluster() method which returns a Credis_Cluster object that contains both the master server and a random slave. Credis_Cluster takes care of the read/write splitting
Автор: Thijs Feryn ([email protected])
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_client Credis_Client Sentinel uses the same protocol as Redis which makes using Credis_Client convenient.
$_cluster array Contains an active instance of Credis_Cluster per master pool
$_master array Contains an active instance of Credis_Client representing a master
$_password string Store the AUTH password used by Credis_Client instances
$_slaves array Contains an array Credis_Client objects representing all slaves per master pool
$_standAlone boolean Use the phpredis extension or the standalone implementation

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

Метод Описание
__call ( string $name, array $args ) : mixed Catch-all method
__construct ( Credis_Client $client, string $password = NULL ) Connect with a Sentinel node. Sentinel will do the master and slave discovery
createCluster ( string $name, integer $db, integer $replicas = 128, boolean $selectRandomSlave = true, boolean $writeOnly = false ) : Credis_Cluster Returns a Redis cluster object containing a random slave and the master When $selectRandomSlave is true, only one random slave is passed.
createMasterClient ( string $name ) : Credis_Client Discover the master node automatically and return an instance of Credis_Client that connects to the master
createSlaveClients ( string $name ) : Credis_Client[] Discover the slave nodes automatically and return an array of Credis_Client objects
failover ( string $name ) : mixed Perform an auto-failover which will re-elect another master and make the current master a slave
forceStandalone ( ) : Credis_Sentinel
getCluster ( string $name, integer $db, integer $replicas = 128, boolean $selectRandomSlave = true, boolean $writeOnly = false ) : Credis_Cluster If a Credis_Cluster object exists, return it. Otherwise create one and return it.
getHost ( ) : string
getMasterAddressByName ( string $name ) : mixed Get the hostname and port for a specific master
getMasterClient ( string $name ) : Credis_Client If a Credis_Client object exists for a master, return it. Otherwise create one and return it
getPort ( ) : integer
getSlaveClients ( string $name ) : Credis_Client[] If an array of Credis_Client objects exist for a set of slaves, return them. Otherwise create and return them
master ( string $name ) : mixed Get the information for a specific master
masters ( ) : mixed Return information about all registered master servers
ping ( ) : mixed Check if the Sentinel is still responding
setClientDatabase ( integer $db )
setClientPassword ( null | string $password )
setClientPersistent ( string $persistent )
setClientTimeout ( float $timeout )
slaves ( string $name ) : mixed Return all information for slaves that are associated with a single master

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

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

Catch-all method
public __call ( string $name, array $args ) : mixed
$name string
$args array
Результат mixed

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

Connect with a Sentinel node. Sentinel will do the master and slave discovery
public __construct ( Credis_Client $client, string $password = NULL )
$client Credis_Client
$password string (deprecated - use setClientPassword)

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

When $selectRandomSlave is false, all clients are passed and hashing is applied in Credis_Cluster When $writeOnly is false, the master server will also be used for read commands.
Устаревший:
public createCluster ( string $name, integer $db, integer $replicas = 128, boolean $selectRandomSlave = true, boolean $writeOnly = false ) : Credis_Cluster
$name string
$db integer
$replicas integer
$selectRandomSlave boolean
$writeOnly boolean
Результат Credis_Cluster

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

Discover the master node automatically and return an instance of Credis_Client that connects to the master
public createMasterClient ( string $name ) : Credis_Client
$name string
Результат Credis_Client

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

Discover the slave nodes automatically and return an array of Credis_Client objects
public createSlaveClients ( string $name ) : Credis_Client[]
$name string
Результат Credis_Client[]

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

Perform an auto-failover which will re-elect another master and make the current master a slave
public failover ( string $name ) : mixed
$name string
Результат mixed

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

Устаревший:
public forceStandalone ( ) : Credis_Sentinel
Результат Credis_Sentinel

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

If a Credis_Cluster object exists, return it. Otherwise create one and return it.
Устаревший:
public getCluster ( string $name, integer $db, integer $replicas = 128, boolean $selectRandomSlave = true, boolean $writeOnly = false ) : Credis_Cluster
$name string
$db integer
$replicas integer
$selectRandomSlave boolean
$writeOnly boolean
Результат Credis_Cluster

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

public getHost ( ) : string
Результат string

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

Get the hostname and port for a specific master
public getMasterAddressByName ( string $name ) : mixed
$name string
Результат mixed

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

If a Credis_Client object exists for a master, return it. Otherwise create one and return it
public getMasterClient ( string $name ) : Credis_Client
$name string
Результат Credis_Client

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

public getPort ( ) : integer
Результат integer

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

If an array of Credis_Client objects exist for a set of slaves, return them. Otherwise create and return them
public getSlaveClients ( string $name ) : Credis_Client[]
$name string
Результат Credis_Client[]

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

Get the information for a specific master
public master ( string $name ) : mixed
$name string
Результат mixed

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

Return information about all registered master servers
public masters ( ) : mixed
Результат mixed

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

Check if the Sentinel is still responding
public ping ( ) : mixed
Результат mixed

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

public setClientDatabase ( integer $db )
$db integer

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

public setClientPassword ( null | string $password )
$password null | string

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

public setClientPersistent ( string $persistent )
$persistent string

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

public setClientTimeout ( float $timeout )
$timeout float

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

Return all information for slaves that are associated with a single master
public slaves ( string $name ) : mixed
$name string
Результат mixed

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

$_client защищенное свойство

Sentinel uses the same protocol as Redis which makes using Credis_Client convenient.
protected Credis_Client $_client
Результат Credis_Client

$_cluster защищенное свойство

Contains an active instance of Credis_Cluster per master pool
protected array $_cluster
Результат array

$_master защищенное свойство

Contains an active instance of Credis_Client representing a master
protected array $_master
Результат array

$_password защищенное свойство

Store the AUTH password used by Credis_Client instances
protected string $_password
Результат string

$_slaves защищенное свойство

Contains an array Credis_Client objects representing all slaves per master pool
protected array $_slaves
Результат array

$_standAlone защищенное свойство

Use the phpredis extension or the standalone implementation
Устаревший:
protected bool $_standAlone
Результат boolean