* 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 );
// 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 );
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)
}
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;
}
break;
default:
$msg = $this->client->getResultMessage();
- $logCtx = array();
+ $logCtx = [];
if ( $key !== false ) {
$server = $this->client->getServerByKey( $key );
$logCtx['memcached-server'] = "{$server['host']}:{$server['port']}";
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 );
}
* @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 );
}
+
+ public function changeTTL( $key, $expiry = 0 ) {
+ $this->debugLog( "touch($key)" );
+ $result = $this->client->touch( $key, $expiry );
+ return $this->checkResult( $key, $result );
+ }
}