From: Aaron Schulz Date: Fri, 1 Mar 2013 22:53:48 +0000 (-0800) Subject: Resolve config defaults in RedisConnectionPool in the singleton(). X-Git-Tag: 1.31.0-rc.0~20448^2 X-Git-Url: http://git.cyclocoop.org/url?a=commitdiff_plain;h=1ca99fa95743cb30ff45602655bd1233f4ee2e4e;p=lhc%2Fweb%2Fwiklou.git Resolve config defaults in RedisConnectionPool in the singleton(). * This can avoid fragmentation when applying defaults to different config arrays actually gives the same resulting array. Change-Id: Iacab8d38080f51eb3f331d55a8535eed6d93b381 --- diff --git a/includes/clientpool/RedisConnectionPool.php b/includes/clientpool/RedisConnectionPool.php index bb8b77f965..e81bc5debd 100644 --- a/includes/clientpool/RedisConnectionPool.php +++ b/includes/clientpool/RedisConnectionPool.php @@ -72,18 +72,10 @@ class RedisConnectionPool { throw new MWException( __CLASS__. ' requires the phpredis extension: ' . 'https://github.com/nicolasff/phpredis' ); } - $this->connectTimeout = isset( $options['connectTimeout'] ) - ? $options['connectTimeout'] - : 1; - $this->persistent = isset( $options['persistent'] ) - ? $options['persistent'] - : false; - $this->password = isset( $options['password'] ) - ? $options['password'] - : ''; - $this->poolSize = isset( $options['poolSize'] ) - ? $options['poolSize'] - : 5; + $this->connectTimeout = $options['connectTimeout']; + $this->persistent = $options['persistent']; + $this->password = $options['password']; + $this->poolSize = $options['poolSize']; if ( !isset( $options['serializer'] ) || $options['serializer'] === 'php' ) { $this->serializer = Redis::SERIALIZER_PHP; } elseif ( $options['serializer'] === 'igbinary' ) { @@ -93,11 +85,32 @@ class RedisConnectionPool { } } + /** + * @param $options Array + * @return Array + */ + protected static function applyDefaultConfig( array $options ) { + if ( !isset( $options['connectTimeout'] ) ) { + $options['connectTimeout'] = 1; + } + if ( !isset( $options['persistent'] ) ) { + $options['persistent'] = false; + } + if ( !isset( $options['password'] ) ) { + $options['password'] = ''; + } + if ( !isset( $options['poolSize'] ) ) { + $options['poolSize'] = 1; + } + return $options; + } + /** * @param $options Array * @return RedisConnectionPool */ public static function singleton( array $options ) { + $options = self::applyDefaultConfig( $options ); // Map the options to a unique hash... $poolOptions = $options; unset( $poolOptions['poolSize'] ); // avoid pool fragmentation @@ -109,7 +122,7 @@ class RedisConnectionPool { wfDebug( "Creating a new " . __CLASS__ . " instance with id $id." ); } // Simply grow the pool size if the existing one is too small - $psize = isset( $options['poolSize'] ) ? $options['poolSize'] : 1; // size requested + $psize = $options['poolSize']; // size requested self::$instances[$id]->poolSize = max( $psize, self::$instances[$id]->poolSize ); return self::$instances[$id];