memcached on win

memcached是一个很好的分布式缓存,在linux上安装很方便,以前在win试过,没弄成功。今天showsa告诉我有一个win上的移植,这就方便多了。
http://jehiah.com/projects/memcached-win32/
如果下载的是二进制的版本,直接运行就可以了,可以加上参数来加以设置。
常用设置:
-p           监听的端口
-l      连接的IP地址, 默认是本机
-d start          启动memcached服务
-d restart        重起memcached服务
-d stop|shutdown  关闭正在运行的memcached服务
-d install        安装memcached服务
-d uninstall      卸载memcached服务
-u      以的身份运行 (仅在以root运行的时候有效)
-m           最大内存使用,单位MB。默认64MB
-M                内存耗尽时返回错误,而不是删除项
-c           最大同时连接数,默认是1024
-f        块大小增长因子,默认是1.25
-n         最小分配空间,key+value+flags默认是48
-h                显示帮助

然后就可以用php的memcached客户端来试一下了。
<?php
//test1.php
$memcache = new Memcache;
$memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
$memcache->set(‘test’, ‘hello’);
?>

<?php
//test2.php
$memcache = new Memcache;
$memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
echo $memcache->get(‘test’);
?>
依次运行test1.php, test2.php,就可以看到,放在memcached里的”hello”。
具体的用法可以看php手册,这里就不多说了。

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s