python---windows下安装和使用memcache

时间:2023-03-09 00:07:24
python---windows下安装和使用memcache

windows版本下memcache地址http://www.runoob.com/memcached/window-install-memcached.html

注意当选择版本>=1.45时需要设置,将 memcached 添加来任务计划表中

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

然后在命令行中开启服务:

C:\Users\Administrator>memcached  -m  -u root -l 127.0.0.1 -p  -c  -P c:\memcached.pid

在python中安装memcache模块

pip3 install python-memcached

python代码测试:

import memcache

mc  = memcache.Client(['127.0.0.1:8081'],debug=True)#开发模式开启debug,会显示错误信息,生成模式时去掉
mc.set('foo',"bar")#memcache只支持键值对形式
ret= mc.get('foo')
print(ret)

输出:bar,成功安装

更多知识扩展:点击此处