Skip to content

Commit dbc2c23

Browse files
authored
Merge pull request #32924 from nextcloud/memcached-binary-protocol
Enable binary protocol again
2 parents f46d839 + 90104bc commit dbc2c23

File tree

1 file changed

+6
-24
lines changed

1 file changed

+6
-24
lines changed

lib/private/Memcache/Memcached.php

+6-24
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct($prefix = '') {
6363
\Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
6464

6565
// Enable Binary Protocol
66-
//\Memcached::OPT_BINARY_PROTOCOL => true,
66+
\Memcached::OPT_BINARY_PROTOCOL => true,
6767
];
6868
/**
6969
* By default enable igbinary serializer if available
@@ -119,10 +119,7 @@ public function set($key, $value, $ttl = 0) {
119119
} else {
120120
$result = self::$cache->set($this->getNameSpace() . $key, $value);
121121
}
122-
if ($result !== true) {
123-
$this->verifyReturnCode();
124-
}
125-
return $result;
122+
return $result || $this->isSuccess();
126123
}
127124

128125
public function hasKey($key) {
@@ -132,10 +129,7 @@ public function hasKey($key) {
132129

133130
public function remove($key) {
134131
$result = self::$cache->delete($this->getNameSpace() . $key);
135-
if (self::$cache->getResultCode() !== \Memcached::RES_NOTFOUND) {
136-
$this->verifyReturnCode();
137-
}
138-
return $result;
132+
return $result || $this->isSuccess() || self::$cache->getResultCode() === \Memcached::RES_NOTFOUND;
139133
}
140134

141135
public function clear($prefix = '') {
@@ -151,14 +145,10 @@ public function clear($prefix = '') {
151145
* @param mixed $value
152146
* @param int $ttl Time To Live in seconds. Defaults to 60*60*24
153147
* @return bool
154-
* @throws \Exception
155148
*/
156149
public function add($key, $value, $ttl = 0) {
157150
$result = self::$cache->add($this->getPrefix() . $key, $value, $ttl);
158-
if (self::$cache->getResultCode() !== \Memcached::RES_NOTSTORED) {
159-
$this->verifyReturnCode();
160-
}
161-
return $result;
151+
return $result || $this->isSuccess();
162152
}
163153

164154
/**
@@ -200,15 +190,7 @@ public static function isAvailable(): bool {
200190
return extension_loaded('memcached');
201191
}
202192

203-
/**
204-
* @throws \Exception
205-
*/
206-
private function verifyReturnCode() {
207-
$code = self::$cache->getResultCode();
208-
if ($code === \Memcached::RES_SUCCESS) {
209-
return;
210-
}
211-
$message = self::$cache->getResultMessage();
212-
throw new \Exception("Error $code interacting with memcached : $message");
193+
private function isSuccess(): bool {
194+
return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
213195
}
214196
}

0 commit comments

Comments
 (0)