Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/51794
Change subject: Resolve config defaults in RedisConnectionPool in the singleton(). ...................................................................... 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 --- M includes/clientpool/RedisConnectionPool.php 1 file changed, 26 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/94/51794/1 diff --git a/includes/clientpool/RedisConnectionPool.php b/includes/clientpool/RedisConnectionPool.php index bb8b77f..e81bc5d 100644 --- a/includes/clientpool/RedisConnectionPool.php +++ b/includes/clientpool/RedisConnectionPool.php @@ -72,18 +72,10 @@ 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' ) { @@ -95,9 +87,30 @@ /** * @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 @@ 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]; -- To view, visit https://gerrit.wikimedia.org/r/51794 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iacab8d38080f51eb3f331d55a8535eed6d93b381 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits