python memcache安装与使用

来源:互联网 发布:被淘宝卖家骚扰怎么办 编辑:程序博客网 时间:2024/05/20 04:11


1. 下载memcached

wget http://www.danga.com/memcached/dist/memcached-1.2.0.tar.gz

2. 下载libevent

wget http://www.monkey.org/~provos/libevent-1.2.tar.gz

3. 先安装libevent

$ tar zxvf libevent-1.2.tar.gz

$ cd libevent-1.2

$ ./configure prefix=/usr

$ make

$ make install

4. 安装memcached

$ tar zxvf memcached-1.2.0.tar.gz

$ cd memcached-1.2.0

$ ./configure with-libevent=/usr   # 注意这个配置跟着libevent

$ make

$ make install

$ /usr/local/bin/memcached -m 10 -p 12000 -u root 

5. 如果启动Memcached服务的时候遇到了

/usr/local/bin/memcached: error while loading shared libraries: libevent-1.2.so.1: cannot open shared object file: No such file or directory;

[root@localhost bin]# LD_DEBUG=libs memcached -v 
[root@localhost bin]# ln -s /usr/lib/libevent-1.2.so.1 /usr/lib64/libevent-1.2.so.1
[root@localhost bin]# usr/local/bin/memcached -m 10 -p 12000 -u root 


6. Python-memcached安装

http://www.cnblogs.com/chenli0513/admin/ftp://ftp.tummy.com/pub/python-memcached/下载最新版本的API,并解压tar包输入python setup.py install命令进行安装

#!/usr/bin/env python

import memcache

mc = memcache.Client(['127.0.0.1:12000 ],debug=0)

mc.set("foo","bar")

value = mc.get("foo")

print value

bar



原创粉丝点击