1

如果我运行以下脚本,它会在设置时引发异常。

缓冲测试.py

import pylibmc
mc = pylibmc.Client(['localhost:11211'], behaviors={'buffer_requests': True})
mc.set('key1', 'value1')
print 'Reaching here'
print mc.get('key1')

输出 :

root@shady:~# python buffertest.py 
Traceback (most recent call last):
  File "buffertest.py", line 3, in <module>
    mc.set('key1', 'value1')
_pylibmc.MemcachedError: error 32 from memcached_set: SUCCESS

如果我捕捉到那个异常,那么 get 会抛出一个错误:

import pylibmc
mc = pylibmc.Client(['localhost:11211'], behaviors={'buffer_requests': True})
try:   
        mc.set('key1', 'value1')
except:
        pass
print 'Reaching here'
print mc.get('key1')

输出:

root@shady:~# python buffertest.py
Reaching here
Traceback (most recent call last):
  File "buffertest.py", line 8, in <module>
    print mc.get('key1')
_pylibmc.MemcachedError: error 47 from memcached_get(key1): SERVER HAS FAILED AND IS    DISABLED UNTIL TIMED RETRY                                                                                                                                                                                     

我是否以错误的方式使用这种行为?我对这种行为的理解是 - 集合将在客户端缓冲,并在第一次到达时刷新到服务器。为什么会导致服务器错误?

4

1 回答 1

0

尝试将二进制选项设置为 False:

mc = pylibmc.Client(['localhost:11211'], binary=False, behaviors={'buffer_requests': True})
于 2013-03-10T17:31:17.187 回答