PHP 8.3.4 Released!

Memcached::getDelayed

(PECL memcached >= 0.1.0)

Memcached::getDelayed请求多个元素

说明

public Memcached::getDelayed(array $keys, bool $with_cas = false, ?callable $value_cb = null): bool

Memcached::getDelayed() 向 Memcached 服务端发出一个检索 keys 指定的多个 key 对应元素的请求。这个方法不会等待响应而是立即返回。当你需要收集元素值时,调用 Memcached::fetch()Memcached::fetchAll()。如果 with_cas 设置为 true,会同时请求每个元素的 CAS 标记。

可以通过参数 value_cb 指定一个 result callback 来替代明确的抓取结果(fetch 或 fetchAll 为明确抓取方式)。

参数

keys

要请求的 key 的数组。

with_cas

是否同时请求 CAS 标记。

value_cb

结果回调函数或 null

返回值

成功时返回 true, 或者在失败时返回 false。 如需要则使用 Memcached::getResultCode()

示例

示例 #1 Memcached::getDelayed() 示例

<?php
$m
= new Memcached();
$m->addServer('localhost', 11211);

$m->set('int', 99);
$m->set('string', 'a simple string');
$m->set('array', array(11, 12));

$m->getDelayed(array('int', 'array'), true);
var_dump($m->fetchAll());
?>

以上示例会输出:

array(2) {
  [0]=>
  array(3) {
    ["key"]=>
    string(3) "int"
    ["value"]=>
    int(99)
    ["cas"]=>
    float(2363)
  }
  [1]=>
  array(3) {
    ["key"]=>
    string(5) "array"
    ["value"]=>
    array(2) {
      [0]=>
      int(11)
      [1]=>
      int(12)
    }
    ["cas"]=>
    float(2365)
  }
}

参见

add a note

User Contributed Notes 1 note

up
2
antmat at mail dot ru
13 years ago
Actually, when you pass a callback, method doesn't return immediately, but waits for results and calls callback function.
To Top