我正在使用python。我做了一个 yum install memcached 然后是一个 easy_install python-memcached
我使用了帮助(memcache)中的简单测试程序。当我没有得到正确的答案时,我抛出了一些打印语句:
[~/test]$ cat m2.py
import memcache
mc = memcache.Client(['127.0.0.1:11211'], debug=0)
x = mc.set("some_key", "Some value")
print 'Just set a key and value into the cache (suposedly)'
value = mc.get("some_key")
print 'Just retrieved that value from the cache using the key'
print 'X %s' % x
print 'Value %s' % value
[~/test]$ python m2.py
Just set a key and value into the cache (suposedly)
Just retrieved that value from the cache using the key
X 0
Value None
[~/test]$
现在的问题是,我在安装中没有做些什么?从 API 的角度来看,它似乎正在工作,但它无法将任何内容放入内存缓存共享区域。我正在使用运行 centos [~]# cat /proc/version Linux 版本 2.6.32-358.6.2.el6.i686 的 virtualbox vm (mockbuild@c6b8.bsys.dev.centos.org) (gcc 版本 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) ) #1 SMP Thu May 16 18:12:13 UTC 2013
是否有应该运行的守护进程?当我做 ps 时,我没有看到一个明显的名字。
我试图在我的 vm 上安装 pylibmc,但找不到有效的安装,所以现在看看我是否可以先让上述东西工作。
我发现如果我直接从 python 控制台 GUI 运行,如果我设置 debug=1,我会得到更多的输出
>>> mc = memcache.Client(['127.0.0.1:11211'], debug=1)
>>> mc.stats
{}
>>> mc.set('test','value')
MemCached: MemCache: inet:127.0.0.1:11211: connect: Connection refused. Marking dead.
0
>>> mc.get('test')
MemCached: MemCache: inet:127.0.0.1:11211: connect: Connection refused. Marking dead.
当我尝试使用示例 telnet 连接到端口时,连接被拒绝:
[root@~]# telnet 127.0.0.1 11211
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
[root@~]#
我尝试了我在网上找到的配置 telnet 的说明,这样 localhost 就不会被禁用: vi /etc/xinetd.d/telnet service telnet { flags = REUSE socket_type = stream wait = no user = root server = /usr/sbin /in.telnetd log_on_failure += USERID disable = no }
然后运行命令重新启动服务:
service iptables stop
service xinetd stop
service iptables start
service xinetd start
service iptables stop
我运行了这两种情况(iptables 启动和停止),但它没有效果。所以我没有想法。我需要做什么才能允许使用 PORT?如果那是问题?或者是否需要运行需要打开端口的 memcached 服务?