Memcache::getExtendedStats> <Memcache::flush
Last updated: Mon, 28 Dec 2009

Memcache::get

(PECL memcache:0.2-2.1.2)

Memcache::get — Retrieve item from the server

Descrição

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

Memcache::get() returns previously stored data if an item with such key exists on the server at this moment.

You can pass array of keys to Memcache::get() to get array of values. The result array will contain only found key-value pairs.

Parâmetros

key

The key or array of keys to fetch.

flags

If present, flags fetched along with the values will be written to this parameter. These flags are the same as the ones given to for example Memcache::set(). The lowest byte of the int is reserved for pecl/memcache internal usage (e.g. to indicate compression and serialization status).

Valor Retornado

Returns the string associated with the key or FALSE on failure or if such key was not found.

Exemplos

Exemplo #1 Memcache::get() example

<?php

/* procedural API */
$memcache_obj memcache_connect('memcache_host'11211);
$var memcache_get($memcache_obj'some_key');

/* OO API */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host'11211);
$var $memcache_obj->get('some_key');

/* 
You also can use array of keys as a parameter.
If such item wasn't found at the server, the result
array simply will not include such key.
*/

/* procedural API */
$memcache_obj memcache_connect('memcache_host'11211);
$var memcache_get($memcache_obj, Array('some_key''another_key'));

/* OO API */
$memcache_obj = new Memcache;
$memcache_obj->connect('memcache_host'11211);
$var $memcache_obj->get(Array('some_key''second_key'));

?>



User Contributed Notes
Memcache::get
nate at mailinator dot com
08-Oct-2007 01:50
Just a warning: the PHP Memcache class completely breaks the second you try to get() a key that was not set by the PHP Memcache class. Specifically, if any flags are present on an entry in Memcache, PHP doesn't know what to do and will close your connection to the cache.

Took me quite a while to find out why I kept losing my connection to Memcache; of course, it's because I was trying to get() memcache keys that had flags=30 set.

Lesson: stick to writing your own customized memcache class that connects via tcp and deals with flags the way you want them dealt with.

Memcache::getExtendedStats> <Memcache::flush
Last updated: Mon, 28 Dec 2009