PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Memcache::getExtendedStats> <Memcache::flush
Last updated: Fri, 29 Aug 2008

view this page in

Memcache::get

(PECL memcache:0.2-2.1.2)

Memcache::getサーバから項目を取得する

説明

string Memcache::get ( string $key [, int &$flags ] )
array Memcache::get ( array $keys [, array &$flags ] )

Memcache::get() は、その時点でサーバ上に key というキーのデータが存在する場合に、 格納されているデータを返します。

Memcache::get() にキーの配列を渡すことにより、 値の配列を取得することができます。この配列には、サーバ上で見つかった キーと値のペアのみが含まれます。

パラメータ

key

取得したいキー (あるいはキーの配列)。

flags

存在した場合は、値とともに取得したフラグをここに書き込みます。 これらのフラグは、たとえば Memcache::set() に渡すものと同じです。int の最下位バイトは pecl/memcache で内部的に使用するために予約されています (たとえば圧縮やシリアライズに関する状態を表します)。

返り値

key に関連付けられた文字列を返します。 取得に失敗したり key が見つからなかったりした 場合には FALSE を返します。

例1 Memcache::get() の例

<?php

/* 手続き型の API */
$memcache_obj memcache_connect('memcache_host'11211);
$var memcache_get($memcache_obj'some_key');

/* オブジェクト指向の API */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host'11211);
$var $memcache_obj->get('some_key');

/* 
キーの配列をパラメータとして使用することもできます。
もしキーに対応する項目がサーバ上で見つからなければ、
結果の配列の中にはそのキーは含まれません。
*/

/* 手続き型の API */
$memcache_obj memcache_connect('memcache_host'11211);
$var memcache_get($memcache_obj, Array('some_key''another_key'));

/* オブジェクト指向の API */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host'11211);
$var $memcache_obj->get(Array('some_key''second_key'));

?>



add a note add a note User Contributed Notes
Memcache::get
marko at nastja dot com
30-Jul-2008 09:07
It looks like memcache take only first 256 characters. So if you want to cache some (large) queries do md5 or similar before caching.
jakub dot lopuszanski at nasza-klasa dot pl
07-Jul-2008 11:39
If deserialization fails for some reason, that is when memcache server returned flag 1 set, but the value was not a correctly serialized PHP data,
then Memcache::get acts in a following way:

If it was called with a single key to retrieve, then a warning is raised, but since it was not actually a bug of a server, the warning says something confusing like "Memcached Server Error: null" and the function returns bool(false).

If it was called by passing an array (even with a single element in it), then the warning is not raised and the resulting array contains a value bool(false).

Since there are some buffer overrun bugs present in Memcached Server, which from time to time cause overwriting of [part of] data and therefore rendering it impossible to deserialize, make sure to check if the result of Memcache::get contains only string, or deserialized structure. If the result is bool,dobule or long, then something went wrong.

Memcache::getExtendedStats> <Memcache::flush
Last updated: Fri, 29 Aug 2008
 
 
show source | credits | sitemap | contact | advertising | mirror sites