Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Add workaround to use Memcached 3.0.0 with Many, Fix issues in #13002 #15739

Merged
merged 1 commit into from
Oct 5, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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