<?php
/**
- * PhpRedis client connection pooling manager.
+ * Redis client connection pooling manager.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
/**
- * Helper class to manage redis connections using PhpRedis.
+ * 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.
* @since 1.21
*/
class RedisConnectionPool {
- // Settings for all connections in this pool
- protected $connectTimeout; // string; connection timeout
- protected $persistent; // bool; whether connections persist
- protected $password; // string; plaintext auth password
- protected $serializer; // integer; the serializer to use (Redis::SERIALIZER_*)
+ /**
+ * @name Pool settings.
+ * Settings there are shared for any connection made in this pool.
+ * See the singleton() method documentation for more details.
+ * @{
+ */
+ /** @var string Connection timeout in seconds */
+ protected $connectTimeout;
+ /** @var string Plaintext auth password */
+ protected $password;
+ /** @var bool Whether connections persist */
+ protected $persistent;
+ /** @var integer Serializer to use (Redis::SERIALIZER_*) */
+ protected $serializer;
+ /** @} */
- protected $idlePoolSize = 0; // integer; current idle pool size
+ /** @var integer Current idle pool size */
+ protected $idlePoolSize = 0;
/** @var Array (server name => ((connection info array),...) */
protected $connections = array();
/** @var Array (server name => UNIX timestamp) */
protected $downServers = array();
- /** @var Array */
- protected static $instances = array(); // (pool ID => RedisConnectionPool)
+ /** @var Array (pool ID => RedisConnectionPool) */
+ protected static $instances = array();
- const SERVER_DOWN_TTL = 30; // integer; seconds to cache servers as "down"
+ /** integer; seconds to cache servers as "down". */
+ const SERVER_DOWN_TTL = 30;
/**
* @param array $options
*/
protected function __construct( array $options ) {
- if ( !extension_loaded( 'redis' ) ) {
- throw new MWException( __CLASS__ . ' requires the phpredis extension: ' .
- 'https://github.com/nicolasff/phpredis' );
+ if ( !class_exists( 'Redis' ) ) {
+ throw new MWException( __CLASS__ . ' requires a Redis client library. ' .
+ 'See https://www.mediawiki.org/wiki/Redis#Setup' );
}
$this->connectTimeout = $options['connectTimeout'];
$this->persistent = $options['persistent'];
}
if ( $conn->getLastError() ) { // script bug?
- wfDebugLog( 'redis', "Lua script error: " . $conn->getLastError() );
+ $server = $this->server;
+ wfDebugLog( 'redis', "Lua script error on server $server: " . $conn->getLastError() );
}
return $res;