|
MediaWiki master
|
Manage one or more Redis client connection. More...
Inherits LoggerAwareInterface.

Public Member Functions | |
| __destruct () | |
| Make sure connections are closed. | |
| freeConnection ( $server, Redis $conn) | |
| Mark a connection to a server as free to return to the pool. | |
| getConnection ( $server, ?LoggerInterface $logger=null) | |
| 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. | |
| 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. | |
| setLogger (LoggerInterface $logger) | |
Static Public Member Functions | |
| static | destroySingletons () |
| Destroy all singleton() instances. | |
| static | singleton (array $options) |
Protected Member Functions | |
| __construct (array $options, $id) | |
| 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 = [] |
| (server name => ((connection info array),...) | |
| int | $connectTimeout |
| Connection timeout in seconds. | |
| array | $downServers = [] |
| (server name => UNIX timestamp) | |
| string | $id |
| ID for persistent connections. | |
| int | $idlePoolSize = 0 |
| Current idle pool size. | |
| LoggerInterface | $logger |
| string string[] null | $password |
| Plaintext auth password or array containing username and password. | |
| bool | $persistent |
| Whether connections persist. | |
| string null | $prefix |
| Key prefix automatically added to all operations. | |
| string | $readTimeout |
| Read timeout in seconds. | |
| int | $serializer |
| Serializer to use (Redis::SERIALIZER_*) | |
Static Protected Attributes | |
| static array | $instances = [] |
| (pool ID => RedisConnectionPool) | |
Manage one or more Redis client connection.
This can be used to get RedisConnRef objects that automatically reuses connections internally after the calling function has returned (and thus your RedisConnRef instance leaves scope/destructs).
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 33 of file RedisConnectionPool.php.
|
protected |
| array | $options | |
| string | $id |
| Exception |
Definition at line 76 of file RedisConnectionPool.php.
References Wikimedia\ObjectCache\RedisConnectionPool\$id.
| Wikimedia\ObjectCache\RedisConnectionPool::__destruct | ( | ) |
Make sure connections are closed.
Definition at line 406 of file RedisConnectionPool.php.
|
staticprotected |
|
protected |
Close any extra idle connections if there are more than the limit.
Definition at line 320 of file RedisConnectionPool.php.
|
static |
Destroy all singleton() instances.
Definition at line 164 of file RedisConnectionPool.php.
| Wikimedia\ObjectCache\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 301 of file RedisConnectionPool.php.
| Wikimedia\ObjectCache\RedisConnectionPool::getConnection | ( | $server, | |
| ?LoggerInterface | $logger = null ) |
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. |
| LoggerInterface | null | $logger | PSR-3 logger instance. [optional] |
| InvalidArgumentException |
Definition at line 177 of file RedisConnectionPool.php.
| Wikimedia\ObjectCache\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 346 of file RedisConnectionPool.php.
References Wikimedia\ObjectCache\RedisConnRef\getServer(), and Wikimedia\ObjectCache\RedisConnRef\isConnIdentical().
| Wikimedia\ObjectCache\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 380 of file RedisConnectionPool.php.
| Wikimedia\ObjectCache\RedisConnectionPool::resetTimeout | ( | Redis | $conn, |
| $timeout = null ) |
Adjust or reset the connection handle read timeout value.
| Redis | $conn | |
| int | null | $timeout | Optional |
Definition at line 399 of file RedisConnectionPool.php.
| Wikimedia\ObjectCache\RedisConnectionPool::setLogger | ( | LoggerInterface | $logger | ) |
Definition at line 104 of file RedisConnectionPool.php.
|
static |
| array | $options | $options include:
|
Definition at line 147 of file RedisConnectionPool.php.
Referenced by Wikimedia\ObjectCache\RedisBagOStuff\__construct(), and MediaWiki\JobQueue\JobQueueRedis\__construct().
|
protected |
(server name => ((connection info array),...)
Definition at line 56 of file RedisConnectionPool.php.
|
protected |
Connection timeout in seconds.
Definition at line 35 of file RedisConnectionPool.php.
|
protected |
(server name => UNIX timestamp)
Definition at line 58 of file RedisConnectionPool.php.
|
protected |
ID for persistent connections.
Definition at line 47 of file RedisConnectionPool.php.
Referenced by Wikimedia\ObjectCache\RedisConnectionPool\__construct().
|
protected |
Current idle pool size.
Definition at line 50 of file RedisConnectionPool.php.
|
staticprotected |
(pool ID => RedisConnectionPool)
Definition at line 61 of file RedisConnectionPool.php.
|
protected |
Definition at line 69 of file RedisConnectionPool.php.
|
protected |
Plaintext auth password or array containing username and password.
Definition at line 39 of file RedisConnectionPool.php.
|
protected |
Whether connections persist.
Definition at line 43 of file RedisConnectionPool.php.
|
protected |
Key prefix automatically added to all operations.
Definition at line 41 of file RedisConnectionPool.php.
|
protected |
Read timeout in seconds.
Definition at line 37 of file RedisConnectionPool.php.
|
protected |
Serializer to use (Redis::SERIALIZER_*)
Definition at line 45 of file RedisConnectionPool.php.