MediaWiki
REL1_24
|
Helper class to manage Redis connections. More...
Public Member Functions | |
__destruct () | |
Make sure connections are closed for sanity. | |
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. | |
handleError (RedisConnRef $cref, RedisException $e) | |
The redis extension throws an exception in response to various read, write and protocol errors. | |
handleException ($server, RedisConnRef $cref, RedisException $e) | |
The redis extension throws an exception in response to various read, write and protocol errors. | |
reauthenticateConnection ($server, Redis $conn) | |
Re-send an AUTH request to the redis server (useful after disconnects). | |
resetTimeout (Redis $conn, $timeout=null) | |
Adjust or reset the connection handle read timeout value. | |
Static Public Member Functions | |
static | singleton (array $options) |
Public Attributes | |
const | SERVER_DOWN_TTL = 30 |
integer; seconds to cache servers as "down". | |
Protected Member Functions | |
__construct (array $options) | |
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),...) * | |
array | $downServers = array() |
(server name => UNIX timestamp) * | |
int | $idlePoolSize = 0 |
Current idle pool size *. | |
Pool settings. | |
Settings there are shared for any connection made in this pool. See the singleton() method documentation for more details. | |
string | $connectTimeout |
Connection timeout in seconds *. | |
string | $readTimeout |
Read timeout in seconds *. | |
string | $password |
Plaintext auth password *. | |
bool | $persistent |
Whether connections persist *. | |
int | $serializer |
Serializer to use (Redis::SERIALIZER_*) *. | |
Static Protected Attributes | |
static | $instances = array() |
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.
Definition at line 38 of file RedisConnectionPool.php.
RedisConnectionPool::__construct | ( | array $ | options | ) | [protected] |
array | $options |
MWException |
Definition at line 67 of file RedisConnectionPool.php.
Make sure connections are closed for sanity.
Definition at line 350 of file RedisConnectionPool.php.
static RedisConnectionPool::applyDefaultConfig | ( | array $ | options | ) | [static, protected] |
RedisConnectionPool::closeExcessIdleConections | ( | ) | [protected] |
Close any extra idle connections if there are more than the limit.
Definition at line 256 of file RedisConnectionPool.php.
RedisConnectionPool::freeConnection | ( | $ | server, |
Redis $ | conn | ||
) |
Mark a connection to a server as free to return to the pool.
string | $server | |
Redis | $conn |
Definition at line 237 of file RedisConnectionPool.php.
References as.
RedisConnectionPool::getConnection | ( | $ | server | ) |
Get a connection to a redis server.
Based on code in RedisBagOStuff.php.
string | $server | A hostname/port combination or the absolute path of a UNIX socket. If a hostname is specified but no port, port 6379 will be used. |
MWException |
Definition at line 145 of file RedisConnectionPool.php.
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.
RedisConnRef | $cref | |
RedisException | $e |
Definition at line 297 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.
string | $server | |
RedisConnRef | $cref | |
RedisException | $e |
Definition at line 284 of file RedisConnectionPool.php.
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.
string | $server | |
Redis | $conn |
Definition at line 325 of file RedisConnectionPool.php.
RedisConnectionPool::resetTimeout | ( | Redis $ | conn, |
$ | timeout = null |
||
) |
Adjust or reset the connection handle read timeout value.
Redis | $conn | |
int | $timeout | Optional |
Definition at line 343 of file RedisConnectionPool.php.
static RedisConnectionPool::singleton | ( | array $ | options | ) | [static] |
array | $options | $options include:
|
Definition at line 123 of file RedisConnectionPool.php.
Referenced by PoolCounterRedis\__construct(), and RedisPubSubFeedEngine\send().
(server name => ((connection info array),...) *
Definition at line 54 of file RedisConnectionPool.php.
string RedisConnectionPool::$connectTimeout [protected] |
Connection timeout in seconds *.
Definition at line 45 of file RedisConnectionPool.php.
(server name => UNIX timestamp) *
Definition at line 55 of file RedisConnectionPool.php.
int RedisConnectionPool::$idlePoolSize = 0 [protected] |
Current idle pool size *.
Definition at line 52 of file RedisConnectionPool.php.
RedisConnectionPool::$instances = array() [static, protected] |
Definition at line 58 of file RedisConnectionPool.php.
string RedisConnectionPool::$password [protected] |
Plaintext auth password *.
Definition at line 47 of file RedisConnectionPool.php.
bool RedisConnectionPool::$persistent [protected] |
Whether connections persist *.
Definition at line 48 of file RedisConnectionPool.php.
string RedisConnectionPool::$readTimeout [protected] |
Read timeout in seconds *.
Definition at line 46 of file RedisConnectionPool.php.
int RedisConnectionPool::$serializer [protected] |
Serializer to use (Redis::SERIALIZER_*) *.
Definition at line 49 of file RedisConnectionPool.php.
const RedisConnectionPool::SERVER_DOWN_TTL = 30 |
integer; seconds to cache servers as "down".
Definition at line 61 of file RedisConnectionPool.php.