X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fobjectcache%2FMemcachedPeclBagOStuff.php;h=090ace8538150a46f11450b251cfd146218a4d35;hp=a7b48a2a2e8123bdf240f5f4640163734be9e541;hb=708c02281e6e8880ae2cebbda7f353ce97841f94;hpb=ecaa5e87af254096793e3b6dd3aee7df0ec4e4f0 diff --git a/includes/objectcache/MemcachedPeclBagOStuff.php b/includes/objectcache/MemcachedPeclBagOStuff.php index a7b48a2a2e..090ace8538 100644 --- a/includes/objectcache/MemcachedPeclBagOStuff.php +++ b/includes/objectcache/MemcachedPeclBagOStuff.php @@ -43,7 +43,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { * values, but serialization is much slower unless the php.ini option * igbinary.compact_strings is off. * @param array $params - * @throws MWException + * @throws InvalidArgumentException */ function __construct( $params ) { parent::__construct( $params ); @@ -89,7 +89,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { // is as good as any. There's no way to configure libmemcached to use // hashes identical to the ones currently in use by the PHP client, and // even implementing one of the libmemcached hashes in pure PHP for - // forwards compatibility would require MWMemcached::get_sock() to be + // forwards compatibility would require MemcachedClient::get_sock() to be // rewritten. $this->client->setOption( Memcached::OPT_LIBKETAMA_COMPATIBLE, true ); @@ -100,15 +100,19 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { break; case 'igbinary': if ( !Memcached::HAVE_IGBINARY ) { - throw new MWException( __CLASS__ . ': the igbinary extension is not available ' . - 'but igbinary serialization was requested.' ); + throw new InvalidArgumentException( + __CLASS__ . ': the igbinary extension is not available ' . + 'but igbinary serialization was requested.' + ); } $this->client->setOption( Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY ); break; default: - throw new MWException( __CLASS__ . ': invalid value for serializer parameter' ); + throw new InvalidArgumentException( + __CLASS__ . ': invalid value for serializer parameter' + ); } - $servers = array(); + $servers = []; foreach ( $params['servers'] as $host ) { $servers[] = IP::splitHostAndPort( $host ); // (ip, port) } @@ -117,38 +121,21 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { protected function getWithToken( $key, &$casToken, $flags = 0 ) { $this->debugLog( "get($key)" ); - $result = $this->client->get( $this->encodeKey( $key ), null, $casToken ); + $result = $this->client->get( $this->validateKeyEncoding( $key ), null, $casToken ); $result = $this->checkResult( $key, $result ); return $result; } - /** - * @param string $key - * @param mixed $value - * @param int $exptime - * @return bool - */ - public function set( $key, $value, $exptime = 0 ) { + public function set( $key, $value, $exptime = 0, $flags = 0 ) { $this->debugLog( "set($key)" ); return $this->checkResult( $key, parent::set( $key, $value, $exptime ) ); } - /** - * @param float $casToken - * @param string $key - * @param mixed $value - * @param int $exptime - * @return bool - */ protected function cas( $casToken, $key, $value, $exptime = 0 ) { $this->debugLog( "cas($key)" ); return $this->checkResult( $key, parent::cas( $casToken, $key, $value, $exptime ) ); } - /** - * @param string $key - * @return bool - */ public function delete( $key ) { $this->debugLog( "delete($key)" ); $result = parent::delete( $key ); @@ -160,33 +147,17 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { } } - /** - * @param string $key - * @param int $value - * @param int $exptime - * @return mixed - */ public function add( $key, $value, $exptime = 0 ) { $this->debugLog( "add($key)" ); return $this->checkResult( $key, parent::add( $key, $value, $exptime ) ); } - /** - * @param string $key - * @param int $value - * @return mixed - */ public function incr( $key, $value = 1 ) { $this->debugLog( "incr($key)" ); $result = $this->client->increment( $key, $value ); return $this->checkResult( $key, $result ); } - /** - * @param string $key - * @param int $value - * @return mixed - */ public function decr( $key, $value = 1 ) { $this->debugLog( "decr($key)" ); $result = $this->client->decrement( $key, $value ); @@ -218,7 +189,7 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { break; default: $msg = $this->client->getResultMessage(); - $logCtx = array(); + $logCtx = []; if ( $key !== false ) { $server = $this->client->getServerByKey( $key ); $logCtx['memcached-server'] = "{$server['host']}:{$server['port']}"; @@ -235,14 +206,10 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { public function getMulti( array $keys, $flags = 0 ) { $this->debugLog( 'getMulti(' . implode( ', ', $keys ) . ')' ); - $callback = array( $this, 'encodeKey' ); - $encodedResult = $this->client->getMulti( array_map( $callback, $keys ) ); - $encodedResult = $encodedResult ?: array(); // must be an array - $result = array(); - foreach ( $encodedResult as $key => $value ) { - $key = $this->decodeKey( $key ); - $result[$key] = $value; + foreach ( $keys as $key ) { + $this->validateKeyEncoding( $key ); } + $result = $this->client->getMulti( $keys ) ?: []; return $this->checkResult( false, $result ); } @@ -252,14 +219,10 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff { * @return bool */ public function setMulti( array $data, $exptime = 0 ) { - foreach ( $data as $key => $value ) { - $encKey = $this->encodeKey( $key ); - if ( $encKey !== $key ) { - $data[$encKey] = $value; - unset( $data[$key] ); - } - } $this->debugLog( 'setMulti(' . implode( ', ', array_keys( $data ) ) . ')' ); + foreach ( array_keys( $data ) as $key ) { + $this->validateKeyEncoding( $key ); + } $result = $this->client->setMulti( $data, $this->fixExpiry( $exptime ) ); return $this->checkResult( false, $result ); }