BlueSpice MediaWiki REL1_27
 All Classes Namespaces Files Functions Variables Groups Pages
RedisConnectionPool Class Reference
Inheritance diagram for RedisConnectionPool:
Collaboration diagram for RedisConnectionPool:

Public Member Functions

 setLogger (LoggerInterface $logger)
 
 getConnection ($server)
 
 freeConnection ($server, Redis $conn)
 
 handleException ($server, RedisConnRef $cref, RedisException $e)
 
 handleError (RedisConnRef $cref, RedisException $e)
 
 reauthenticateConnection ($server, Redis $conn)
 
 resetTimeout (Redis $conn, $timeout=null)
 
 __destruct ()
 

Static Public Member Functions

static singleton (array $options)
 
static destroySingletons ()
 

Public Attributes

const SERVER_DOWN_TTL = 30
 

Protected Member Functions

 __construct (array $options)
 
 closeExcessIdleConections ()
 

Static Protected Member Functions

static applyDefaultConfig (array $options)
 

Protected Attributes

 $idlePoolSize = 0
 
 $connections = []
 
 $downServers = []
 
 $logger
 
Pool settings.

Settings there are shared for any connection made in this pool. See the singleton() method documentation for more details.

 $connectTimeout
 
 $readTimeout
 
 $password
 
 $persistent
 
 $serializer
 

Static Protected Attributes

static $instances = []
 

Detailed Description

Helper class to manage Redis connections.

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

Constructor & Destructor Documentation

RedisConnectionPool::__construct ( array  $options)
protected
Parameters
array$options
Exceptions
Exception
RedisConnectionPool::__destruct ( )

Make sure connections are closed for sanity

Member Function Documentation

static RedisConnectionPool::applyDefaultConfig ( array  $options)
staticprotected
Parameters
array$options
Returns
array
RedisConnectionPool::closeExcessIdleConections ( )
protected

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

static RedisConnectionPool::destroySingletons ( )
static

Destroy all singleton() instances

Since
1.27
RedisConnectionPool::freeConnection (   $server,
Redis  $conn 
)

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

Parameters
string$server
Redis$conn
Returns
bool
RedisConnectionPool::getConnection (   $server)

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
RedisConnectionPool::handleError ( 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
RedisConnRef$cref
RedisException$e
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
string$server
RedisConnRef$cref
RedisException$e
Deprecated:
since 1.23
RedisConnectionPool::reauthenticateConnection (   $server,
Redis  $conn 
)

Re-send an AUTH request to the redis server (useful after disconnects).

This works around an upstream bug in phpredis. phpredis hides disconnects by transparently reconnecting, but it neglects to re-authenticate the new connection. To the user of the phpredis client API this manifests as a seemingly random tendency of connections to lose their authentication status.

This method is for internal use only.

See Also
https://github.com/nicolasff/phpredis/issues/403
Parameters
string$server
Redis$conn
Returns
bool Success
RedisConnectionPool::resetTimeout ( Redis  $conn,
  $timeout = null 
)

Adjust or reset the connection handle read timeout value

Parameters
Redis$conn
int$timeoutOptional
RedisConnectionPool::setLogger ( LoggerInterface  $logger)
Parameters
LoggerInterface$logger
Returns
null

Implements Psr\Log\LoggerAwareInterface.

static RedisConnectionPool::singleton ( array  $options)
static
Parameters
array$options$options include:
  • connectTimeout : The timeout for new connections, in seconds. Optional, default is 1 second.
  • readTimeout : The timeout for operation reads, in seconds. Commands like BLPOP can fail if told to wait longer than this. 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".
Returns
RedisConnectionPool

Member Data Documentation

const RedisConnectionPool::SERVER_DOWN_TTL = 30

integer; seconds to cache servers as "down".


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