2013年7月27日 星期六

memcached quick note

Installation

  • sudo apt-get install memcached

Command line

  •  $ telnet localhost 11211
add foo 0 0 11
hello world
STORED
get foo
VALUE foo 0 11
hello world
END
delete foo
DELETED

PHP extension

  • sudo apt-get install php5-memcached
$m = new Memcached();
$m->addServer('localhost', 11211);

$m->set('int', 99);
$m->set('string', 'a simple string');
$m->set('array', array(11, 12));
/* expire 'object' key in 5 minutes */
$m->set('object', new stdclass, time() + 300);


var_dump($m->get('int'));
var_dump($m->get('string'));
var_dump($m->get('array'));
var_dump($m->get('object'));
?>

Example from: http://www.php.net/manual/en/memcached.set.php

Reference

沒有留言:

張貼留言