简体   繁体   中英

Introduction to Memcached

I am trying to use Memcached right now, and I am a little confuse about this:

First, do I need to make a class for Memcached? like this: click me! or is it automatically works? do I just need to make a connection to the memcached server and then I can cache data?

UPDATE

When I tried to use the code exiang provided, my output in all of the var_dump s are boolean false . Anybody knows why is this happened?

UPDATE PART 2

When I tried to use this code echo $m->getResultMessage(),"\\n"; it returns:

SERVER HAS FAILED AND IS DISABLED UNTIL TIMED RETRY

make sure you have enabled the php memcache module, it looks like this in your phpinfo 在此处输入图片说明

Make sure your memcached server is running

Then, you can use it directly like this: http://php.net/manual/en/memcached.set.php

<?php
$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'));
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM