Memcached::getDelayed

(PECL memcached >= 0.1.0)

Memcached::getDelayed複数のアイテムを要求する

説明

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

Memcached::getDelayed() は、keys 配列で指定した複数のキーのアイテムに対するリクエストを memcache に発行します。 このメソッドはサーバーからの応答を待たずにすぐに結果を返します。 アイテムを使用したくなったときには Memcached::fetch() あるいは Memcached::fetchAll() をコールします。 with_cas が true の場合は CAS トークンの値もリクエストします。

結果を明示的に取得するのではなく、result コールバックvalue_cb パラメータで指定することもできます。

パラメータ

keys

要求するキーの配列。

with_cas

CAS トークンの値も要求するかどうか。

value_cb

result コールバック、あるいは 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) } }

参考

To Top