objectcache: update MemcachedPeclBagOStuff for pecl memcached 3.0.0
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 31 May 2018 21:41:02 +0000 (14:41 -0700)
committerReedy <reedy@wikimedia.org>
Tue, 5 Jun 2018 21:07:37 +0000 (21:07 +0000)
The get() $cas_token parameter was changed into $flags, which can act
as a switch to make the return value an associative array of details.

pecl and PHP-based memcached BagOStuff class both pass all tests now.

Bug: T196125
Change-Id: I4678250331a48db4d50d1fc6c489c991a4dee920

RELEASE-NOTES-1.31
includes/libs/objectcache/MemcachedPeclBagOStuff.php
includes/libs/objectcache/MemcachedPhpBagOStuff.php
tests/phpunit/includes/libs/objectcache/BagOStuffTest.php

index d369ac6..01c3f21 100644 (file)
@@ -410,6 +410,7 @@ changes to languages because of Phabricator reports.
   wikitext table captions, wikitext table headings, wikitext table cells. HTML
   headings, HTML list items, HTML table captions, HTML table headings, HTML
   table cells will not have this trimming behavior.
+* (T196125) php-memcached 3.0 (provided with PHP 7.0) is now supported.
 
 == Compatibility ==
 MediaWiki 1.31 requires PHP 7.0.0 or later. Although HHVM 3.18.5 or later is
index e3e66d5..fe31c25 100644 (file)
@@ -140,7 +140,19 @@ class MemcachedPeclBagOStuff extends MemcachedBagOStuff {
 
        protected function getWithToken( $key, &$casToken, $flags = 0 ) {
                $this->debugLog( "get($key)" );
-               $result = $this->client->get( $this->validateKeyEncoding( $key ), null, $casToken );
+               if ( defined( Memcached::class . '::GET_EXTENDED' ) ) { // v3.0.0
+                       $flags = Memcached::GET_EXTENDED;
+                       $res = $this->client->get( $this->validateKeyEncoding( $key ), null, $flags );
+                       if ( is_array( $res ) ) {
+                               $result = $res['value'];
+                               $casToken = $res['cas'];
+                       } else {
+                               $result = false;
+                               $casToken = null;
+                       }
+               } else {
+                       $result = $this->client->get( $this->validateKeyEncoding( $key ), null, $casToken );
+               }
                $result = $this->checkResult( $key, $result );
                return $result;
        }
index e2d9d93..3ff390b 100644 (file)
@@ -62,12 +62,12 @@ class MemcachedPhpBagOStuff extends MemcachedBagOStuff {
        public function incr( $key, $value = 1 ) {
                $this->validateKeyEncoding( $key );
 
-               return $this->client->incr( $key, $value );
+               return $this->client->incr( $key, $value ) ?? false;
        }
 
        public function decr( $key, $value = 1 ) {
                $this->validateKeyEncoding( $key );
 
-               return $this->client->decr( $key, $value );
+               return $this->client->decr( $key, $value ) ?? false;
        }
 }
index 4320d80..10fba83 100644 (file)
@@ -92,12 +92,12 @@ class BagOStuffTest extends MediaWikiTestCase {
                // merge on non-existing value
                $merged = $this->cache->merge( $key, $callback, 0 );
                $this->assertTrue( $merged );
-               $this->assertEquals( $this->cache->get( $key ), 'merged' );
+               $this->assertEquals( 'merged', $this->cache->get( $key ) );
 
                // merge on existing value
                $merged = $this->cache->merge( $key, $callback, 0 );
                $this->assertTrue( $merged );
-               $this->assertEquals( $this->cache->get( $key ), 'mergedmerged' );
+               $this->assertEquals( 'mergedmerged', $this->cache->get( $key ) );
 
                /*
                 * Test concurrent merges by forking this process, if: