memcached 服务的安装及php-memcached的扩展详见脚本。
安装及启动
yum install libevent libevent-deve memcached -y
memcached -d -u root -m 1024M -p 11211
文档 http://www.php.net/manual/en/book.memcached.php
php-memcached代码的应用:
<?php $mem = new Memcached(); $mem->addServer('10.30.47.25',11211); $mem->add("name","yyydn",3600); // 添加 $mem->replace("name","asd2dan"); //替换 echo $mem->get('name'); //获取 ?>
Node.js memcached 模块查看状态
var Memcached = require('memcached'); var memcached = new Memcached('***I****P***:11211'); memcached.stats(function(err,data){ console.log('memcached进程' + data[0].pid); console.log('分配的内存大小' + (data[0].limit_maxbytes/1048576).toFixed(2) + 'Mb'); console.log('当前存储占用空间' + (data[0].bytes/1048576).toFixed(2) + 'Mb'); console.log('存储占用比' + ((data[0].bytes/data[0].limit_maxbytes).toFixed(4)*100 + '%')); })