MediaWiki  REL1_21
RedisConnectionPool Class Reference

Helper class to manage redis connections using PhpRedis. More...

Collaboration diagram for RedisConnectionPool:

List of all members.

Public Member Functions

 freeConnection ($server, Redis $conn)
 Mark a connection to a server as free to return to the pool.
 getConnection ($server)
 Get a connection to a redis server.
 handleException ($server, RedisConnRef $cref, RedisException $e)
 The redis extension throws an exception in response to various read, write and protocol errors.

Static Public Member Functions

static singleton (array $options)

Public Attributes

const SERVER_DOWN_TTL = 30

Protected Member Functions

 __construct (array $options)
 $options include:
 closeExcessIdleConections ()
 Close any extra idle connections if there are more than the limit.

Static Protected Member Functions

static applyDefaultConfig (array $options)

Protected Attributes

Array $connections = array()
 (server name => ((connection info array),...) *
 $connectTimeout
Array $downServers = array()
 (server name => UNIX timestamp) *
 $idlePoolSize = 0
 $password
 $persistent
 $serializer

Static Protected Attributes

static $instances = array()

Detailed Description

Helper class to manage redis connections using PhpRedis.

This can be used to get handle wrappers that free the handle when the wrapper leaves scope. The maximum number of free handles (connections) is configurable. This provides an easy way to cache connection handles that may also have state, such as a handle does between multi() and exec(), and without hoarding connections. The wrappers use PHP magic methods so that calling functions on them calls the function of the actual Redis object handle.

Since:
1.21

Definition at line 38 of file RedisConnectionPool.php.


Constructor & Destructor Documentation

RedisConnectionPool::__construct ( array options) [protected]

$options include:

  • connectTimeout : The timeout for new connections, in seconds. Optional, default is 1 second.
  • persistent : Set this to true to allow connections to persist across multiple web requests. False by default.
  • password : The authentication password, will be sent to Redis in clear text. Optional, if it is unspecified, no AUTH command will be sent.
  • serializer : Set to "php", "igbinary", or "none". Default is "php".
    Parameters:
    array$options

Definition at line 66 of file RedisConnectionPool.php.


Member Function Documentation

static RedisConnectionPool::applyDefaultConfig ( array options) [static, protected]
Parameters:
$optionsArray
Returns:
Array

Definition at line 89 of file RedisConnectionPool.php.

Close any extra idle connections if there are more than the limit.

Returns:
void

Definition at line 234 of file RedisConnectionPool.php.

RedisConnectionPool::freeConnection ( server,
Redis $  conn 
)

Mark a connection to a server as free to return to the pool.

Parameters:
$serverstring
$connRedis
Returns:
boolean

Definition at line 213 of file RedisConnectionPool.php.

Get a connection to a redis server.

Based on code in RedisBagOStuff.php.

Parameters:
string$serverA hostname/port combination or the absolute path of a UNIX socket. If a hostname is specified but no port, port 6379 will be used.
Returns:
RedisConnRef|bool Returns false on failure
Exceptions:
MWException

Definition at line 127 of file RedisConnectionPool.php.

RedisConnectionPool::handleException ( server,
RedisConnRef cref,
RedisException $  e 
)

The redis extension throws an exception in response to various read, write and protocol errors.

Sometimes it also closes the connection, sometimes not. The safest response for us is to explicitly destroy the connection object and let it be reopened during the next request.

Parameters:
$serverstring
$crefRedisConnRef
$eRedisException
Returns:
void

Definition at line 262 of file RedisConnectionPool.php.

static RedisConnectionPool::singleton ( array options) [static]
Parameters:
$optionsArray
Returns:
RedisConnectionPool

Definition at line 106 of file RedisConnectionPool.php.


Member Data Documentation

Array RedisConnectionPool::$connections = array() [protected]

(server name => ((connection info array),...) *

Definition at line 47 of file RedisConnectionPool.php.

RedisConnectionPool::$connectTimeout [protected]

Definition at line 40 of file RedisConnectionPool.php.

Array RedisConnectionPool::$downServers = array() [protected]

(server name => UNIX timestamp) *

Definition at line 48 of file RedisConnectionPool.php.

RedisConnectionPool::$idlePoolSize = 0 [protected]

Definition at line 45 of file RedisConnectionPool.php.

RedisConnectionPool::$instances = array() [static, protected]

Definition at line 51 of file RedisConnectionPool.php.

RedisConnectionPool::$password [protected]

Definition at line 42 of file RedisConnectionPool.php.

RedisConnectionPool::$persistent [protected]

Definition at line 41 of file RedisConnectionPool.php.

RedisConnectionPool::$serializer [protected]

Definition at line 43 of file RedisConnectionPool.php.

Definition at line 53 of file RedisConnectionPool.php.


The documentation for this class was generated from the following file: