PHP Class 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
Author: Thijs Feryn ([email protected])
显示文件 Open project: colinmollenhour/credis Class Usage Examples

Protected Properties

Property Type Description
$_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

Public Methods

Method Description
__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

Method Details

__call() public method

Catch-all method
public __call ( string $name, array $args ) : mixed
$name string
$args array
return mixed

__construct() public method

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() public method

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.
Deprecation:
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
return Credis_Cluster

createMasterClient() public method

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
return Credis_Client

createSlaveClients() public method

Discover the slave nodes automatically and return an array of Credis_Client objects
public createSlaveClients ( string $name ) : Credis_Client[]
$name string
return Credis_Client[]

failover() public method

Perform an auto-failover which will re-elect another master and make the current master a slave
public failover ( string $name ) : mixed
$name string
return mixed

forceStandalone() public method

Deprecation:
public forceStandalone ( ) : Credis_Sentinel
return Credis_Sentinel

getCluster() public method

If a Credis_Cluster object exists, return it. Otherwise create one and return it.
Deprecation:
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
return Credis_Cluster

getHost() public method

public getHost ( ) : string
return string

getMasterAddressByName() public method

Get the hostname and port for a specific master
public getMasterAddressByName ( string $name ) : mixed
$name string
return mixed

getMasterClient() public method

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
return Credis_Client

getPort() public method

public getPort ( ) : integer
return integer

getSlaveClients() public method

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
return Credis_Client[]

master() public method

Get the information for a specific master
public master ( string $name ) : mixed
$name string
return mixed

masters() public method

Return information about all registered master servers
public masters ( ) : mixed
return mixed

ping() public method

Check if the Sentinel is still responding
public ping ( ) : mixed
return mixed

setClientDatabase() public method

public setClientDatabase ( integer $db )
$db integer

setClientPassword() public method

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

setClientPersistent() public method

public setClientPersistent ( string $persistent )
$persistent string

setClientTimeout() public method

public setClientTimeout ( float $timeout )
$timeout float

slaves() public method

Return all information for slaves that are associated with a single master
public slaves ( string $name ) : mixed
$name string
return mixed

Property Details

$_client protected_oe property

Sentinel uses the same protocol as Redis which makes using Credis_Client convenient.
protected Credis_Client $_client
return Credis_Client

$_cluster protected_oe property

Contains an active instance of Credis_Cluster per master pool
protected array $_cluster
return array

$_master protected_oe property

Contains an active instance of Credis_Client representing a master
protected array $_master
return array

$_password protected_oe property

Store the AUTH password used by Credis_Client instances
protected string $_password
return string

$_slaves protected_oe property

Contains an array Credis_Client objects representing all slaves per master pool
protected array $_slaves
return array

$_standAlone protected_oe property

Use the phpredis extension or the standalone implementation
Deprecation:
protected bool $_standAlone
return boolean