2 // @generated by docskel.php
5 * Represents a connection to a set of memcached servers.
7 <<__NativeData("MemcachedData")>>
10 * Create a Memcached instance
12 * @param string $persistent_id - By default the Memcached instances are
13 * destroyed at the end of the request. To create an instance that persists
14 * between requests, use persistent_id to specify a unique ID for the
15 * instance. All instances created with the same persistent_id will share the
19 public function __construct(?
string $persistent_id = null): void
;
22 * Add an item under a new key
24 * @param string $key -
25 * @param mixed $value -
26 * @param int $expiration -
28 * @return bool - The Memcached::getResultCode will return
29 * Memcached::RES_NOTSTORED if the key already exists.
31 public function add(mixed $key,
33 mixed $expiration = 0): bool {
34 return $this->addByKey('', $key, $value, $expiration);
38 * Add an item under a new key on a specific server
40 * @param string $server_key -
41 * @param string $key -
42 * @param mixed $value -
43 * @param int $expiration -
45 * @return bool - The Memcached::getResultCode will return
46 * Memcached::RES_NOTSTORED if the key already exists.
49 public function addByKey(string $server_key,
52 int $expiration = 0): bool;
55 * Add a server to the server pool
57 * @param string $host - The hostname of the memcache server. If the
58 * hostname is invalid, data-related operations will set
59 * Memcached::RES_HOST_LOOKUP_FAILURE result code.
60 * @param int $port - The port on which memcache is running. Usually,
62 * @param int $weight - The weight of the server relative to the total
63 * weight of all the servers in the pool. This controls the probability
64 * of the server being selected for operations. This is used only with
65 * consistent distribution option and usually corresponds to the amount
66 * of memory available to memcache on that server.
71 public function addServer(string $host,
73 int $weight = 0): bool;
76 * Add multiple servers to the server pool
78 * @param array $servers -
82 public function addServers(array<array<mixed>> $servers): bool {
83 $servers_vals = array_values($servers);
84 foreach($servers_vals as $i => $server) {
85 if (!is_array($server)) {
87 sprintf('Server list entry #%d is not an array', $i +
1),
92 if (count($server) < 1) {
94 sprintf('Could not get server host for entry #%d', $i +
1),
99 if (count($server) < 2) {
101 sprintf('Could not get server port for entry #%d', $i +
1),
107 $host = (string)$server[0];
108 $port = (int)$server[1];
109 if (count($server) < 3) {
112 $weight = (int)$server[2];
115 if (!$this->addServer($host, $port, $weight)) {
117 sprintf('Could not add entry #%d to the server list', $i +
1),
126 * Append data to an existing item
128 * @param string $key -
129 * @param string $value - The string to append.
131 * @return bool - The Memcached::getResultCode will return
132 * Memcached::RES_NOTSTORED if the key does not exist.
134 public function append(mixed $key,
135 mixed $value): bool {
136 return $this->appendByKey('', $key, $value);
140 * Append data to an existing item on a specific server
142 * @param string $server_key -
143 * @param string $key -
144 * @param string $value - The string to append.
146 * @return bool - The Memcached::getResultCode will return
147 * Memcached::RES_NOTSTORED if the key does not exist.
150 public function appendByKey(string $server_key,
152 string $value): bool;
155 * Compare and swap an item
157 * @param float $cas_token - Unique value associated with the existing
158 * item. Generated by memcache.
159 * @param string $key -
160 * @param mixed $value -
161 * @param int $expiration -
163 * @return bool - The Memcached::getResultCode will return
164 * Memcached::RES_DATA_EXISTS if the item you are trying to store has
165 * been modified since you last fetched it.
167 public function cas(float $cas_token,
170 int $expiration = 0): bool {
171 return $this->casByKey($cas_token, '', $key, $value, $expiration);
175 * Compare and swap an item on a specific server
177 * @param float $cas_token - Unique value associated with the existing
178 * item. Generated by memcache.
179 * @param string $server_key -
180 * @param string $key -
181 * @param mixed $value -
182 * @param int $expiration -
184 * @return bool - The Memcached::getResultCode will return
185 * Memcached::RES_DATA_EXISTS if the item you are trying to store has
186 * been modified since you last fetched it.
189 public function casByKey(float $cas_token,
193 int $expiration = 0): bool;
196 * Decrement numeric item's value
198 * @param string $key - The key of the item to decrement.
199 * @param int $offset - The amount by which to decrement the item's
201 * @param int $initial_value - The value to set the item to if it
202 * doesn't currently exist.
203 * @param int $expiry - The expiry time to set on the item.
205 * @return int - Returns item's new value on success.
207 public function decrement(string $key,
209 int $initial_value = 0,
210 int $expiry = 0): mixed {
211 return $this->decrementByKey('', $key, $offset, $initial_value, $expiry);
215 * Decrement numeric item's value, stored on a specific server
217 * @param string $server_key -
218 * @param string $key - The key of the item to decrement.
219 * @param int $offset - The amount by which to decrement the item's
221 * @param int $initial_value - The value to set the item to if it
222 * doesn't currently exist.
223 * @param int $expiry - The expiry time to set on the item.
225 * @return int - Returns item's new value on success.
228 public function decrementByKey(string $server_key,
231 int $initial_value = 0,
232 int $expiry = 0): mixed;
237 * @param string $key - The key to be deleted.
238 * @param int $time - The amount of time the server will wait to delete
241 * @return bool - The Memcached::getResultCode will return
242 * Memcached::RES_NOTFOUND if the key does not exist.
244 public function delete(mixed $key,
245 mixed $time = 0): bool {
246 return $this->deleteByKey('', $key, $time);
250 * Delete an item from a specific server
252 * @param string $server_key -
253 * @param string $key - The key to be deleted.
254 * @param int $time - The amount of time the server will wait to delete
257 * @return bool - The Memcached::getResultCode will return
258 * Memcached::RES_NOTFOUND if the key does not exist.
261 public function deleteByKey(string $server_key,
263 int $time = 0): bool;
266 * Fetch the next result
268 * @return array - Returns the next result or FALSE otherwise. The
269 * Memcached::getResultCode will return Memcached::RES_END if result
273 public function fetch(): mixed;
276 * Fetch all the remaining results
278 * @return array - Returns the results.
281 public function fetchAll(): mixed;
284 * Invalidate all items in the cache
286 * @param int $delay - Numer of seconds to wait before invalidating the
292 public function flush(int $delay = 0): bool;
297 * @param string $key - The key of the item to retrieve.
298 * @param callable $cache_cb - Read-through caching callback or NULL.
299 * @param float $cas_token - The variable to store the CAS token in.
301 * @return mixed - Returns the value stored in the cache or FALSE
302 * otherwise. The Memcached::getResultCode will return
303 * Memcached::RES_NOTFOUND if the key does not exist.
305 public function get(mixed $key,
306 ?
mixed $cache_cb = null,
307 ?
mixed &$cas_token = null): mixed {
308 return $this->getByKey('', $key, $cache_cb, $cas_token);
311 /* Memcached::getAllKeys() Gets the keys stored on all the servers
312 * @return mixed - Returns the keys stored on all the servers on success or
316 public function getAllKeys(): mixed;
319 * Retrieve an item from a specific server
321 * @param string $server_key -
322 * @param string $key - The key of the item to fetch.
323 * @param mixed $cache_cb - Read-through caching callback or NULL
324 * @param float $cas_token - The variable to store the CAS token in.
326 * @return mixed - Returns the value stored in the cache or FALSE
327 * otherwise. The Memcached::getResultCode will return
328 * Memcached::RES_NOTFOUND if the key does not exist.
331 public function getByKey(string $server_key,
333 mixed $cache_cb = null,
334 mixed &$cas_token = null): mixed;
337 * Request multiple items
339 * @param array $keys - Array of keys to request.
340 * @param bool $with_cas - Whether to request CAS token values also.
341 * @param callable $value_cb - The result callback or NULL.
345 public function getDelayed(mixed $keys,
346 mixed $with_cas = false,
347 mixed $value_cb = null): bool {
348 return $this->getDelayedByKey('', $keys, $with_cas, $value_cb);
352 * Request multiple items from a specific server
354 * @param string $server_key -
355 * @param array $keys - Array of keys to request.
356 * @param bool $with_cas - Whether to request CAS token values also.
357 * @param callable $value_cb - The result callback or NULL.
362 public function getDelayedByKey(string $server_key,
364 bool $with_cas = false,
365 ?callable
$value_cb = null): bool;
368 * Retrieve multiple items
370 * @param array $keys - Array of keys to retrieve.
371 * @param array $cas_tokens - The variable to store the CAS tokens for
373 * @param int $flags - The flags for the get operation.
375 * @return mixed - Returns the array of found items.
377 public function getMulti(mixed $keys,
378 mixed &$cas_tokens = null,
379 mixed $flags = 0): mixed {
380 return $this->getMultiByKey('', $keys, $cas_tokens, $flags);
384 * Retrieve multiple items from a specific server
386 * @param string $server_key -
387 * @param array $keys - Array of keys to retrieve.
388 * @param string $cas_tokens - The variable to store the CAS tokens for
390 * @param int $flags - The flags for the get operation.
392 * @return array - Returns the array of found items.
395 public function getMultiByKey(string $server_key,
397 mixed &$cas_tokens = null,
398 int $flags = 0): mixed;
401 * Retrieve a Memcached option value
403 * @param int $option - One of the Memcached::OPT_* constants.
405 * @return mixed - Returns the value of the requested option, or FALSE
409 public function getOption(int $option): mixed;
412 * Return the result code of the last operation
414 * @return int - Result code of the last Memcached operation.
417 public function getResultCode(): int;
420 * Return the message describing the result of the last operation
422 * @return string - Message describing the result of the last Memcached
426 public function getResultMessage(): string;
429 * Map a key to a server
431 * @param string $server_key -
433 * @return array - Returns an array containing three keys of host,
434 * port, and weight on success or FALSE on failure.
437 public function getServerByKey(string $server_key): mixed;
440 * Get the list of the servers in the pool
442 * @return array - The list of all servers in the server pool.
445 public function getServerList(): array;
448 * Clears all server from the list
450 * @return bool - Returns TRUE on success or FALSE on failure.
453 public function resetServerList(): bool;
456 * Get server pool statistics
458 * @return array - Array of server statistics, one entry per server.
461 public function getStats(): mixed;
464 * Get server pool version info
466 * @return array - Array of server versions, one entry per server.
469 public function getVersion(): mixed;
472 * Increment numeric item's value
474 * @param string $key - The key of the item to increment.
475 * @param int $offset - The amount by which to increment the item's
477 * @param int $initial_value - The value to set the item to if it
478 * doesn't currently exist.
479 * @param int $expiry - The expiry time to set on the item.
481 * @return int - Returns new item's value on success.
484 public function increment(string $key,
486 int $initial_value = 0,
487 int $expiry = 0): mixed;
490 * Increment numeric item's value, stored on a specific server
492 * @param string $server_key -
493 * @param string $key - The key of the item to increment.
494 * @param int $offset - The amount by which to increment the item's
496 * @param int $initial_value - The value to set the item to if it
497 * doesn't currently exist.
498 * @param int $expiry - The expiry time to set on the item.
500 * @return int - Returns new item's value on success.
503 public function incrementByKey(string $server_key,
506 int $initial_value = 0,
507 int $expiry = 0): mixed;
510 * Prepend data to an existing item
512 * @param string $key - The key of the item to prepend the data to.
513 * @param string $value - The string to prepend.
515 * @return bool - The Memcached::getResultCode will return
516 * Memcached::RES_NOTSTORED if the key does not exist.
518 public function prepend(mixed $key,
519 mixed $value): bool {
520 return $this->prependByKey('', $key, $value);
524 * Prepend data to an existing item on a specific server
526 * @param string $server_key -
527 * @param string $key - The key of the item to prepend the data to.
528 * @param string $value - The string to prepend.
530 * @return bool - The Memcached::getResultCode will return
531 * Memcached::RES_NOTSTORED if the key does not exist.
534 public function prependByKey(string $server_key,
536 string $value): bool;
539 * Replace the item under an existing key
541 * @param string $key -
542 * @param mixed $value -
543 * @param int $expiration -
545 * @return bool - The Memcached::getResultCode will return
546 * Memcached::RES_NOTSTORED if the key does not exist.
548 public function replace(mixed $key,
550 mixed $expiration = 0): bool {
551 return $this->replaceByKey('', $key, $value, $expiration);
555 * Replace the item under an existing key on a specific server
557 * @param string $server_key -
558 * @param string $key -
559 * @param mixed $value -
560 * @param int $expiration -
562 * @return bool - The Memcached::getResultCode will return
563 * Memcached::RES_NOTSTORED if the key does not exist.
566 public function replaceByKey(string $server_key,
569 int $expiration = 0): bool;
574 * @param string $key -
575 * @param mixed $value -
576 * @param int $expiration -
580 public function set(mixed $key,
582 mixed $expiration = 0): bool {
583 return $this->setByKey('', $key, $value, $expiration);
587 * Store an item on a specific server
589 * @param string $server_key -
590 * @param string $key -
591 * @param mixed $value -
592 * @param int $expiration -
597 public function setByKey(string $server_key,
600 int $expiration = 0): bool;
603 * Store multiple items
605 * @param array $items -
606 * @param int $expiration -
610 public function setMulti(array<string, mixed> $items,
611 int $expiration = 0): bool {
612 return $this->setMultiByKey('', $items, $expiration);
616 * Store multiple items on a specific server
618 * @param string $server_key -
619 * @param array $items -
620 * @param int $expiration -
624 public function setMultiByKey(string $server_key,
625 array<string, mixed> $items,
626 int $expiration = 0): bool {
627 foreach($items as $key => $value) {
628 if (!is_string($key)) {
631 if (!$this->setByKey($server_key, $key, $value, $expiration)) {
639 * Set a Memcached option
641 * @param int $option -
642 * @param mixed $value -
647 public function setOption(int $option,
651 * Set Memcached options
653 * @param array $options -
657 public function setOptions(array<int, mixed> $options): bool {
658 foreach($options as $option => $value) {
659 if (!$this->setOption($option, $value)) {
668 class MemcachedException
{