在pylibmc中启用buffer_request行为的正确方法是什么?

时间:2013-01-25 08:47:25

标签: python memcached

如果我运行以下脚本,它会在set处抛出异常。

buffertest.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

如果我捕获该异常,则会抛出错误:

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                                                                                                                                                                                     

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

1 个答案:

答案 0 :(得分:0)

尝试将二元期权设置为False:

mc = pylibmc.Client(['localhost:11211'], binary=False, behaviors={'buffer_requests': True})