8000 Add workaround to use Memcached 3.0.0 for PHP7 with Many, Fix issues … · laravel/framework@38e247e · GitHub
[go: up one dir, main page]

Skip to content

Commit 38e247e

Browse files
committed
Add workaround to use Memcached 3.0.0 for PHP7 with Many, Fix issues in #13002 with < 3.0.0
1 parent ffbd31b commit 38e247e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/Illuminate/Cache/MemcachedStore.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Memcached;
66
use Carbon\Carbon;
77
use Illuminate\Contracts\Cache\Store;
8+
use ReflectionMethod;
89

910
class MemcachedStore extends TaggableStore implements Store
1011
{
@@ -22,6 +23,13 @@ class MemcachedStore extends TaggableStore implements Store
2223
*/
2324
protected $prefix;
2425

26+
/**
27+
* A flag indicating whether the Memcached version is >= 3.0.0
28+
*
29+
* @var bool
30+
*/
31+
protected $memcached_version_3_0;
32+
2533
/**
2634
* Create a new Memcached store.
2735
*
@@ -33,6 +41,7 @@ public function __construct($memcached, $prefix = '')
3341
{
3442
$this->setPrefix($prefix);
3543
$this->memcached = $memcached;
44+
$this->memcached_version_3_0 = (new ReflectionMethod('Memcached', 'getMulti'))->getNumberOfParameters() == 2;
3645
}
3746

3847
/**
@@ -64,7 +73,12 @@ public function many(array $keys)
6473
return $this->prefix.$key;
6574
}, $keys);
6675

67-
$values = $this->memcached->getMulti($prefixedKeys, null, Memcached::GET_PRESERVE_ORDER);
76+
if ($this->memcached_version_3_0) {
77+
$values = $this->memcached->getMulti($prefixedKeys, Memcached::GET_PRESERVE_ORDER);
78+
} else {
79+
$null = null;
80+
$values = $this->memcached->getMulti($prefixedKeys, $null, Memcached::GET_PRESERVE_ORDER);
81+
}
6882

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

0 commit comments

Comments
 (0)
0