Skip to content

Commit

Permalink
Add workaround to use Memcached 3.0.0 for PHP7 with Many, Fix issues in
Browse files Browse the repository at this point in the history
#13002 with < 3.0.0
  • Loading branch information
nikkiii committed Oct 3, 2016
1 parent ffbd31b commit 38e247e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Illuminate/Cache/MemcachedStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Memcached;
use Carbon\Carbon;
use Illuminate\Contracts\Cache\Store;
use ReflectionMethod;

class MemcachedStore extends TaggableStore implements Store
{
Expand All @@ -22,6 +23,13 @@ class MemcachedStore extends TaggableStore implements Store
*/
protected $prefix;

/**
* A flag indicating whether the Memcached version is >= 3.0.0
*
* @var bool
*/
protected $memcached_version_3_0;

/**
* Create a new Memcached store.
*
Expand All @@ -33,6 +41,7 @@ public function __construct($memcached, $prefix = '')
{
$this->setPrefix($prefix);
$this->memcached = $memcached;
$this->memcached_version_3_0 = (new ReflectionMethod('Memcached', 'getMulti'))->getNumberOfParameters() == 2;
}

/**
Expand Down Expand Up @@ -64,7 +73,12 @@ public function many(array $keys)
return $this->prefix.$key;
}, $keys);

$values = $this->memcached->getMulti($prefixedKeys, null, Memcached::GET_PRESERVE_ORDER);
if ($this->memcached_version_3_0) {
$values = $this->memcached->getMulti($prefixedKeys, Memcached::GET_PRESERVE_ORDER);
} else {
$null = null;
$values = $this->memcached->getMulti($prefixedKeys, $null, Memcached::GET_PRESERVE_ORDER);
}

if ($this->memcached->getResultCode() != 0) {
return array_fill_keys($keys, null);
Expand Down

0 comments on commit 38e247e

Please sign in to comment.