Fix callback parameters in memcached
[hiphop-php.git] / hphp / runtime / ext / memcached / ext_memcached.php
blob8c09438780a9a1b2be39781b2741201a516f2c2d
1 <?hh
2 // @generated by docskel.php
4 /**
5 * Represents a connection to a set of memcached servers.
6 */
7 <<__NativeData("MemcachedData")>>
8 class Memcached {
9 /**
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
16 * same connection.
18 <<__Native>>
19 public function __construct(?string $persistent_id = null): void;
21 /**
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,
32 mixed $value,
33 mixed $expiration = 0): bool {
34 return $this->addByKey('', $key, $value, $expiration);
37 /**
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.
48 <<__Native>>
49 public function addByKey(string $server_key,
50 string $key,
51 mixed $value,
52 int $expiration = 0): bool;
54 /**
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,
61 * this is 11211.
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.
68 * @return bool -
70 <<__Native>>
71 public function addServer(string $host,
72 int $port,
73 int $weight = 0): bool;
75 /**
76 * Add multiple servers to the server pool
78 * @param array $servers -
80 * @return bool -
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)) {
86 trigger_error(
87 sprintf('Server list entry #%d is not an array', $i + 1),
88 E_WARNING
90 continue;
92 if (count($server) < 1) {
93 trigger_error(
94 sprintf('Could not get server host for entry #%d', $i + 1),
95 E_WARNING
97 continue;
99 if (count($server) < 2) {
100 trigger_error(
101 sprintf('Could not get server port for entry #%d', $i + 1),
102 E_WARNING
104 continue;
107 $host = (string)$server[0];
108 $port = (int)$server[1];
109 if (count($server) < 3) {
110 $weight = 0;
111 } else {
112 $weight = (int)$server[2];
115 if (!$this->addServer($host, $port, $weight)) {
116 trigger_error(
117 sprintf('Could not add entry #%d to the server list', $i + 1),
118 E_WARNING
122 return true;
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.
149 <<__Native>>
150 public function appendByKey(string $server_key,
151 string $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,
168 string $key,
169 mixed $value,
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.
188 <<__Native>>
189 public function casByKey(float $cas_token,
190 string $server_key,
191 string $key,
192 mixed $value,
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
200 * value.
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,
208 int $offset = 1,
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
220 * value.
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.
227 <<__Native>>
228 public function decrementByKey(string $server_key,
229 string $key,
230 int $offset = 1,
231 int $initial_value = 0,
232 int $expiry = 0): mixed;
235 * Delete an item
237 * @param string $key - The key to be deleted.
238 * @param int $time - The amount of time the server will wait to delete
239 * the item.
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
255 * the item.
257 * @return bool - The Memcached::getResultCode will return
258 * Memcached::RES_NOTFOUND if the key does not exist.
260 <<__Native>>
261 public function deleteByKey(string $server_key,
262 string $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
270 * set is exhausted.
272 <<__Native>>
273 public function fetch(): mixed;
276 * Fetch all the remaining results
278 * @return array - Returns the results.
280 <<__Native>>
281 public function fetchAll(): mixed;
284 * Invalidate all items in the cache
286 * @param int $delay - Numer of seconds to wait before invalidating the
287 * items.
289 * @return bool -
291 <<__Native>>
292 public function flush(int $delay = 0): bool;
295 * Retrieve an item
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
313 * FALSE on failure.
315 <<__Native>>
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.
330 <<__Native>>
331 public function getByKey(string $server_key,
332 string $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.
343 * @return bool -
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.
359 * @return bool -
361 <<__Native>>
362 public function getDelayedByKey(string $server_key,
363 array $keys,
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
372 * the found items.
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
389 * the found items.
390 * @param int $flags - The flags for the get operation.
392 * @return array - Returns the array of found items.
394 <<__Native>>
395 public function getMultiByKey(string $server_key,
396 array $keys,
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
406 * on error.
408 <<__Native>>
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.
416 <<__Native>>
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
423 * operation.
425 <<__Native>>
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.
436 <<__Native>>
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.
444 <<__Native>>
445 public function getServerList(): array;
448 * Clears all server from the list
450 * @return bool - Returns TRUE on success or FALSE on failure.
452 <<__Native>>
453 public function resetServerList(): bool;
456 * Get server pool statistics
458 * @return array - Array of server statistics, one entry per server.
460 <<__Native>>
461 public function getStats(): mixed;
464 * Get server pool version info
466 * @return array - Array of server versions, one entry per server.
468 <<__Native>>
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
476 * value.
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.
483 <<__Native>>
484 public function increment(string $key,
485 int $offset = 1,
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
495 * value.
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.
502 <<__Native>>
503 public function incrementByKey(string $server_key,
504 string $key,
505 int $offset = 1,
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.
533 <<__Native>>
534 public function prependByKey(string $server_key,
535 string $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,
549 mixed $value,
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.
565 <<__Native>>
566 public function replaceByKey(string $server_key,
567 string $key,
568 mixed $value,
569 int $expiration = 0): bool;
572 * Store an item
574 * @param string $key -
575 * @param mixed $value -
576 * @param int $expiration -
578 * @return bool -
580 public function set(mixed $key,
581 mixed $value,
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 -
594 * @return bool -
596 <<__Native>>
597 public function setByKey(string $server_key,
598 string $key,
599 mixed $value,
600 int $expiration = 0): bool;
603 * Store multiple items
605 * @param array $items -
606 * @param int $expiration -
608 * @return bool -
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 -
622 * @return bool -
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)) {
629 continue;
631 if (!$this->setByKey($server_key, $key, $value, $expiration)) {
632 return false;
635 return true;
639 * Set a Memcached option
641 * @param int $option -
642 * @param mixed $value -
644 * @return bool -
646 <<__Native>>
647 public function setOption(int $option,
648 mixed $value): bool;
651 * Set Memcached options
653 * @param array $options -
655 * @return bool -
657 public function setOptions(array<int, mixed> $options): bool {
658 foreach($options as $option => $value) {
659 if (!$this->setOption($option, $value)) {
660 return false;
663 return true;
668 class MemcachedException {