python-memcached 无法获取或设置"JAC_SF"



在检查了一大堆东西后,我发现对于一些密钥,python memcached无法获得,或者无法在我的机器上设置它们(Mac OSX 10.9,自制程序memcached 1.4.15,pip安装的python memcached1.53)。

一切都取决于def_get_server(self,key):

如果我们添加两条调试打印输出行,

def _get_server(self, key):
    if isinstance(key, tuple):
        serverhash, key = key
    else:
        serverhash = serverHashFunction(key)
    for i in range(Client._SERVER_RETRIES):
        server = self.buckets[serverhash % len(self.buckets)]
        if server.connect():
            #print "(using server %s)" % server,
            print 'got server {} for {}'.format(serverhash % len(self.buckets),
                                                key)
            return server, key
        print 'server {} failed for {}'.format(serverhash % len(self.buckets),
                                            key)
        serverhash = serverHashFunction(str(serverhash) + str(i))
    return None, None

试图获取或设置密钥"NFL::CAR_TB",

import memcache
mc_cl = memcache.Client('127.0.0.1')
mc_cl.set('JAC_SF', 1)
mc_cl.get('JAC_SF')
mc_cl.set('UAC_SF', 1)
mc_cl.get('UAC_SF')

结果,在我的机器上,

server 3 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 3 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 2 (inet:7:11211 (dead until 1384821475)) failed for JAC_SF
server 5 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 3 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 2 (inet:7:11211 (dead until 1384821475)) failed for JAC_SF
server 3 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 3 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 2 (inet:7:11211 (dead until 1384821475)) failed for JAC_SF
server 5 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 3 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for JAC_SF
server 2 (inet:7:11211 (dead until 1384821475)) failed for JAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for UAC_SF
got server 6 for UAC_SF
server 7 (inet:.:11211 (dead until 1384821475)) failed for UAC_SF
got server 6 for UAC_SF

如果我将get_server更改为(_G)

def _get_server(self, key):
    choices = range(len(self.buckets) - 1)
    random.shuffle(choices)
    if isinstance(key, tuple):
        choice, key = key
    else:
        choice = choices.pop()
    for _ in range(Client._SERVER_RETRIES):
        server = self.buckets[choice]
        if server.connect():
            #print "(using server %s)" % server,
            print 'got server {} for {}'.format(choice,
                                                key)
            return server, key
        print 'server {} ({}) failed for {}'.format(choice, server, key)
        choice = choices.pop()
    return None, None

然后一切都好起来了,

got server 4 for JAC_SF
server 0 (inet:1:11211 (dead until 1384821552)) failed for JAC_SF
server 3 (inet:.:11211 (dead until 1384821552)) failed for JAC_SF
got server 4 for JAC_SF
server 7 (inet:.:11211 (dead until 1384821552)) failed for UAC_SF
server 0 (inet:1:11211 (dead until 1384821552)) failed for UAC_SF
got server 6 for UAC_SF
server 7 (inet:.:11211 (dead until 1384821552)) failed for UAC_SF
server 2 (inet:7:11211 (dead until 1384821552)) failed for UAC_SF
server 5 (inet:.:11211 (dead until 1384821552)) failed for UAC_SF
server 1 (inet:2:11211 (dead until 1384821552)) failed for UAC_SF
got server 6 for UAC_SF
当我试图在我的python程序中设置多个密钥时,得到了非常不一致的结果,导入memcache两小时=2*60*60mc_cl=内存缓存。客户(1270.0.1')映射={…}mc_cl.flush_all()ret=mc_cl.set_multi(映射=映射,时间=两个小时)getret=mc_cl.get_multi(mapping.keys())if len(映射)!=len(getret):print'not set \n\t{}'.format('\n\t'.join([str((k,mapping[k]))for k in[a表示映射中的.keys()如果不在getret.keys()]])在分析了原始memcache输出后,似乎并不是所有的键都被设置好了,也不是所有的密钥都被请求好了。所有的事情都完成了,并且是最新的自制软件和pip,在Mac OSX 10.9上。下面的Memcache输出和读取表明,只有101个键被尝试写入和读取,而有228个项。进口再gamesSet=[]gamesGet=[]open('mmout.log')为f:对于f.read().split('\n')中的行:match=重新匹配('^21确定22好21个已存储

这是我目前正在与python memcached库的编写者/维护者讨论的一个奇怪的问题,https://github.com/linsomniac/python-memcached/issues/21.

随机地,这里出了问题的是第一行,

mc_cl = memcache.Client('127.0.0.1')

客户端需要一个可迭代的,但不确保检查它没有获取字符串,因此以一种非常Python的方式,它将此字符串视为可迭代的并对其进行迭代,设置"1"、"2"one_answers"7"中的每一个和"0"是memcached服务器的IP地址,但真正的困惑开始于"0"实际上是一个有效的IP地址、计算值为0.0.0.0并且由本地memcached服务,如果这就是你的设置方式(我的开发环境就是这样设置的)。

如果你简单地将其更改为

mc_cl = memcache.Client(('127.0.0.1',))

一切都如预期的那样工作,但如果你输入"127.0.0.1"字符串,你不会收到任何错误消息,也不会收到任何未设置密钥的报告,也不会被"获取",只是像上面这样非常不稳定且无法解释的行为。

相关内容

  • 没有找到相关文章

最新更新