如何增加MemCacheProtocol的最大密钥长度?

2024-03-29 10:09:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试更改最大密钥长度 我尝试了以下示例:

from twisted.internet import reactor, protocol
from twisted.protocols.memcache import MemCacheProtocol, DEFAULT_PORT
import string
from twisted.python import log
import sys
log.startLogging(sys.stdout)
def cb(response):
    log.msg(response) 
d = protocol.ClientCreator(reactor, MemCacheProtocol
    ).connectTCP('localhost', DEFAULT_PORT)
def doSomething(proto):
    # Here you call the memcache operations
    return proto.set(string.ascii_letters*5, string.ascii_letters*5)

MemCacheProtocol.MAX_KEY_LENGTH = 1000
d.addCallback(doSomething)
d.addBoth(cb)
d.addBoth(lambda ignore: reactor.stop())
reactor.run()

我总是失败:

[Failure instance: Traceback (failure with no frames): <class 'twisted.protocols.memcache.ClientError'>: bad command line format!

我猜并不是所有的消息都被发送到memcache服务器,结果它返回这个失败 要在memcache中存储长度大于250的密钥,我需要做什么?你知道吗


Tags: fromimportlogdefaultstringportdefsys
1条回答
网友
1楼 · 发布于 2024-03-29 10:09:43

你修改它太晚了。试试这个:

class MyMemCacheProtocol(MemCacheProtocol):

    MAX_KEY_LENGTH = 1000

现在在ClientCreator()调用中使用这个类,而不是原来的类。你知道吗

相关问题 更多 >