Skip to main content
 首页 » 编程设计

python-memcache 不加载/存储任何东西

2024年11月01日9落叶

所以我试用了内存缓存。在我的 Ubuntu 上执行“apt-get install python-memcache”,然后:

>>> import memcache 
>>> s = memcache.Client(["127.0.0.1:11211"]) 
>>> s.set("mykey", "myvalue") 
0 
>>> myvar = s.get("mykey") 
>>> print(myvar) 
None 

出了什么问题?

请您参考如下方法:

您没有运行 memcached 服务。下面是服务启动时的样子:

>>> s = memcache.Client(["127.0.0.1:11211"]) 
>>> s.set("mykey", "myvalue") 
True 
>>> myvar = s.get("mykey") 
>>> print(myvar) 
myvalue 

以下是检查它是否正在运行的方法:

$ service memcached status 
 * memcached is running