Memcache::get

(no version information, might be only in CVS)

Memcache::get -- Retrieve item from the server

Description

string Memcache::get ( string key )

string Memcache::get ( array keys )

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

例子 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'));

?>

Memcache::get() returns FALSE on failure or if such key was not found.


add a note add a note User Contributed Notes
tszming at gmail dot com
16-Oct-2006 12:14
pls aware of the get() function will change the content of your variable:

e.g.

$key = "this is a test";
$memcache->set($key, 1);

echo $memcache->get($key); // print out "1", as expected
echo $key;                          // print out "this_is_a_test"

i think you would like to use as the following:

$memcache->set("$key", 1);
echo $memcache->get("$key");