X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fobjectcache%2FRedisBagOStuff.php;h=f9d201f489012d9696a55982a2a9583ff1cc8f25;hb=16266edff3337c893a1b5bc42e0bd006a828cde3;hp=e6b3f9eb2f691168985fec80e338217acb7c0cce;hpb=91d69e12e1d2e00953cae3c153e37f3d36e5903c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/objectcache/RedisBagOStuff.php b/includes/objectcache/RedisBagOStuff.php index e6b3f9eb2f..f9d201f489 100644 --- a/includes/objectcache/RedisBagOStuff.php +++ b/includes/objectcache/RedisBagOStuff.php @@ -65,8 +65,8 @@ class RedisBagOStuff extends BagOStuff { */ function __construct( $params ) { parent::__construct( $params ); - $redisConf = array( 'serializer' => 'none' ); // manage that in this class - foreach ( array( 'connectTimeout', 'persistent', 'password' ) as $opt ) { + $redisConf = [ 'serializer' => 'none' ]; // manage that in this class + foreach ( [ 'connectTimeout', 'persistent', 'password' ] as $opt ) { if ( isset( $params[$opt] ) ) { $redisConf[$opt] = $params[$opt]; } @@ -102,7 +102,7 @@ class RedisBagOStuff extends BagOStuff { return $result; } - public function set( $key, $value, $expiry = 0 ) { + public function set( $key, $value, $expiry = 0, $flags = 0 ) { list( $server, $conn ) = $this->getConnection( $key ); if ( !$conn ) { return false; @@ -143,8 +143,8 @@ class RedisBagOStuff extends BagOStuff { } public function getMulti( array $keys, $flags = 0 ) { - $batches = array(); - $conns = array(); + $batches = []; + $conns = []; foreach ( $keys as $key ) { list( $server, $conn ) = $this->getConnection( $key ); if ( !$conn ) { @@ -153,7 +153,7 @@ class RedisBagOStuff extends BagOStuff { $conns[$server] = $conn; $batches[$server][] = $key; } - $result = array(); + $result = []; foreach ( $batches as $server => $batchKeys ) { $conn = $conns[$server]; try { @@ -187,8 +187,8 @@ class RedisBagOStuff extends BagOStuff { * @return bool */ public function setMulti( array $data, $expiry = 0 ) { - $batches = array(); - $conns = array(); + $batches = []; + $conns = []; foreach ( $data as $key => $value ) { list( $server, $conn ) = $this->getConnection( $key ); if ( !$conn ) { @@ -241,7 +241,7 @@ class RedisBagOStuff extends BagOStuff { $result = $conn->set( $key, $this->serialize( $value ), - array( 'nx', 'ex' => $expiry ) + [ 'nx', 'ex' => $expiry ] ); } else { $result = $conn->setnx( $key, $this->serialize( $value ) ); @@ -272,10 +272,10 @@ class RedisBagOStuff extends BagOStuff { if ( !$conn ) { return false; } - if ( !$conn->exists( $key ) ) { - return null; - } try { + if ( !$conn->exists( $key ) ) { + return null; + } // @FIXME: on races, the key may have a 0 TTL $result = $conn->incrBy( $key, $value ); } catch ( RedisException $e ) { @@ -287,6 +287,24 @@ class RedisBagOStuff extends BagOStuff { return $result; } + public function changeTTL( $key, $expiry = 0 ) { + list( $server, $conn ) = $this->getConnection( $key ); + if ( !$conn ) { + return false; + } + + $expiry = $this->convertToRelative( $expiry ); + try { + $result = $conn->expire( $key, $expiry ); + } catch ( RedisException $e ) { + $result = false; + $this->handleException( $conn, $e ); + } + + $this->logRequest( 'expire', $key, $server, $result ); + return $result; + } + public function modifySimpleRelayEvent( array $event ) { if ( array_key_exists( 'val', $event ) ) { $event['val'] = serialize( $event['val'] ); // this class uses PHP serialization @@ -310,7 +328,8 @@ class RedisBagOStuff extends BagOStuff { * @return mixed */ protected function unserialize( $data ) { - return ctype_digit( $data ) ? intval( $data ) : unserialize( $data ); + $int = intval( $data ); + return $data === (string)$int ? $int : unserialize( $data ); } /** @@ -344,7 +363,7 @@ class RedisBagOStuff extends BagOStuff { try { if ( $this->getMasterLinkStatus( $conn ) === 'down' ) { // If the master cannot be reached, fail-over to the next server. - // If masters are in data-center A, and slaves in data-center B, + // If masters are in data-center A, and replica DBs in data-center B, // this helps avoid the case were fail-over happens in A but not // to the corresponding server in B (e.g. read/write mismatch). continue; @@ -356,19 +375,19 @@ class RedisBagOStuff extends BagOStuff { } } - return array( $server, $conn ); + return [ $server, $conn ]; } $this->setLastError( BagOStuff::ERR_UNREACHABLE ); - return array( false, false ); + return [ false, false ]; } /** - * Check the master link status of a Redis server that is configured as a slave. + * Check the master link status of a Redis server that is configured as a replica DB. * @param RedisConnRef $conn * @return string|null Master link status (either 'up' or 'down'), or null - * if the server is not a slave. + * if the server is not a replica DB. */ protected function getMasterLinkStatus( RedisConnRef $conn ) { $info = $conn->info();