文字

Memcached::getDelayed

(PECL memcached >= 0.1.0)

Memcached::getDelayed请求多个元素

说明

public bool Memcached::getDelayed ( array $keys [, bool $with_cas [, callback $value_cb ]] )

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()

范例

Example #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)
  }
}

参见

  • Memcached::getDelayedByKey() - 从指定的服务器上请求多个元素
  • Memcached::fetch() - 抓取下一个结果
  • Memcached::fetchAll() - 抓取所有剩余的结果

用户评论:

[#1] antmat at mail dot ru [2011-02-18 08:16:57]

Actually, when you pass a callback, method doesn't return immediately, but waits for results and calls callback function.

上一篇: 下一篇: