1

我正在尝试更改 MAX_KEY_LENGTH 我尝试了以下示例:

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!

我猜不是所有消息都发送到内存缓存服务器,因此它返回此失败我需要做什么才能将长度大于 250 的密钥存储在内存缓存中?

4

1 回答 1

-1

您修改它为时已晚。试试这个:

class MyMemCacheProtocol(MemCacheProtocol):

    MAX_KEY_LENGTH = 1000

现在在 ClientCreator() 调用中使用这个类而不是原来的。

于 2013-02-19T11:58:50.330 回答