From: Aaron Schulz Date: Sat, 22 Apr 2017 00:17:07 +0000 (-0700) Subject: Set a persistent connection ID for RedisConnectionPool X-Git-Tag: 1.31.0-rc.0~3438^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles_versions%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=0d89c642bde78be0b1093945d69e21bd5e3c6fff;p=lhc%2Fweb%2Fwiklou.git Set a persistent connection ID for RedisConnectionPool This re-uses the options hash as the ID so that re-used connections do not clobber each others settings. Change-Id: I17e5993ecdab1770259803e06956b85b9ebb2ba6 --- diff --git a/includes/libs/redis/RedisConnectionPool.php b/includes/libs/redis/RedisConnectionPool.php index 7f43436c78..e3fc1a629e 100644 --- a/includes/libs/redis/RedisConnectionPool.php +++ b/includes/libs/redis/RedisConnectionPool.php @@ -49,6 +49,8 @@ class RedisConnectionPool implements LoggerAwareInterface { protected $persistent; /** @var int Serializer to use (Redis::SERIALIZER_*) */ protected $serializer; + /** @var string ID for persistent connections */ + protected $id; /** @var int Current idle pool size */ protected $idlePoolSize = 0; @@ -71,9 +73,10 @@ class RedisConnectionPool implements LoggerAwareInterface { /** * @param array $options + * @param string $id * @throws Exception */ - protected function __construct( array $options ) { + protected function __construct( array $options, $id ) { if ( !class_exists( 'Redis' ) ) { throw new RuntimeException( __CLASS__ . ' requires a Redis client library. ' . @@ -95,6 +98,7 @@ class RedisConnectionPool implements LoggerAwareInterface { } else { throw new InvalidArgumentException( "Invalid serializer specified." ); } + $this->id = $id; } /** @@ -148,7 +152,7 @@ class RedisConnectionPool implements LoggerAwareInterface { $id = sha1( serialize( $options ) ); // Initialize the object at the hash as needed... if ( !isset( self::$instances[$id] ) ) { - self::$instances[$id] = new self( $options ); + self::$instances[$id] = new self( $options, $id ); } return self::$instances[$id]; @@ -230,7 +234,7 @@ class RedisConnectionPool implements LoggerAwareInterface { $conn = new Redis(); try { if ( $this->persistent ) { - $result = $conn->pconnect( $host, $port, $this->connectTimeout ); + $result = $conn->pconnect( $host, $port, $this->connectTimeout, $this->id ); } else { $result = $conn->connect( $host, $port, $this->connectTimeout ); }