广告

本站里的文章大部分经过自行整理与测试

2016年5月22日星期日

memcached 安装

Windows 

http://downloads.northscale.com/memcached-win32-1.4.4-14.zip
http://downloads.northscale.com/memcached-win64-1.4.4-14.zip
http://downloads.northscale.com/memcached-1.4.5-x86.zip
http://downloads.northscale.com/memcached-1.4.5-amd64.zip


memcached-1.4.5 以下的安装


c:\memcached\memcached.exe -d install

c:\memcached\memcached.exe -d start
c:\memcached\memcached.exe -d stop
"c:\memcached\memcached.exe" -d runservice -m 512


c:\memcached\memcached.exe -d uninstall

memcached-1.4.5 或以上的安装


schtasks /create /sc onstart /tn memcached /tr "'c:\memcached\memcached.exe' -m 512"
schtasks /delete /tn memcached

php.ini 需要添加


extension=php_memcache.dll
 


Linux

# 去 http://pecl.php.net 下载最新的包, 现在的是memcached-2.2.7.tgz
$ wget http://pecl.php.net/get/memcached-2.2.7.tgz
$ tar zxvf memcached-2.2.7.tgz
$ cd memcached-2.2.7


$ sudo apt-get install php7.0-dev   # 如果已安装 PHP 的话, 就跳过
$ phpize


$ ./configure --enable-memcache --with-php-config=/usr/local/php/bin/php-config -with-zlib-dir


如果 libmemcached 是自己选定位置安装的,
那还要加上-with-libmemcached-dir=<DIR>

$ make && make install

PHP + memcached  整合


$ whereis php  # 找出 php.ini 的位置

$ gedit php.ini
extension=/usr/local/php/lib/php/extensions/xxx/memcached.so

$ php -m   # 会多出 memcached 模块


Python + memcached  整合

pip install python-memcached
pip install python3-memcached


python 代码 

import memcache
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
mc.set("some_key", "Some value")
value = mc.get("some_key")
mc.set("another_key", 3)
mc.delete("another_key")
mc.set("key", "1")   # note that the key used for incr/decr must be a string.
mc.incr("key")
mc.decr("key")

没有评论:

发表评论