protected $password;
/** @var bool Whether connections persist */
protected $persistent;
- /** @var integer Serializer to use (Redis::SERIALIZER_*) */
+ /** @var int Serializer to use (Redis::SERIALIZER_*) */
protected $serializer;
/** @} */
// Initialize the object at the hash as needed...
if ( !isset( self::$instances[$id] ) ) {
self::$instances[$id] = new self( $options );
- wfDebug( "Creating a new " . __CLASS__ . " instance with id $id." );
+ wfDebug( "Creating a new " . __CLASS__ . " instance with id $id.\n" );
}
return self::$instances[$id];
} else {
// Server is dead
wfDebug( "server $server is marked down for another " .
- ( $this->downServers[$server] - $now ) . " seconds, can't get connection" );
+ ( $this->downServers[$server] - $now ) . " seconds, can't get connection\n" );
return false;
}
* @param string $server
* @param RedisConnRef $cref
* @param RedisException $e
+ * @deprecated since 1.23
*/
public function handleException( $server, RedisConnRef $cref, RedisException $e ) {
- wfDebugLog( 'redis', "Redis exception on server $server: " . $e->getMessage() );
+ return $this->handleError( $cref, $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.
+ *
+ * @param RedisConnRef $cref
+ * @param RedisException $e
+ */
+ public function handleError( RedisConnRef $cref, RedisException $e ) {
+ $server = $cref->getServer();
+ wfDebugLog( 'redis', "Redis exception on server $server: " . $e->getMessage() . "\n" );
foreach ( $this->connections[$server] as $key => $connection ) {
if ( $cref->isConnIdentical( $connection['conn'] ) ) {
$this->idlePoolSize -= $connection['free'] ? 1 : 0;
/**
* @param string $script
* @param array $params
- * @param integer $numKeys
+ * @param int $numKeys
* @return mixed
* @throws RedisException
*/
$conn->clearLastError();
$res = $conn->evalSha( $sha1, $params, $numKeys );
// If we got a permission error reply that means that (a) we are not in
- // multi()/pipeline() and (b) some connection problem likely occured. If
+ // multi()/pipeline() and (b) some connection problem likely occurred. If
// the password the client gave was just wrong, an exception should have
// been thrown back in getConnection() previously.
if ( preg_match( '/^ERR operation not permitted\b/', $conn->getLastError() ) ) {