Txredisapi exceptions.RuntimeError:超出最大递归深度

时间:2012-02-01 17:17:42

标签: python redis twisted reactor

我正在尝试删除除Redis中的某些键以外的所有键,并且我确实得到以下异常:

  ... File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twisted/protocols/basic.py", line 572, in dataReceived
    return self.rawDataReceived(data)
  File "build/bdist.macosx-10.6-intel/egg/txredisapi/protocol.py", line 184, in rawDataReceived

  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twisted/protocols/basic.py", line 589, in setLineMode
    return self.dataReceived(extra)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/twisted/protocols/basic.py", line 564, in dataReceived
    why = self.lineReceived(line)
  File "build/bdist.macosx-10.6-intel/egg/txredisapi/protocol.py", line 134, in lineReceived

exceptions.RuntimeError: maximum recursion depth exceeded

以下是代码:

@defer.inlineCallbacks
def resetAll(self):
    dict=yield self.factory.conn.keys()        
    for xyz in dict:
        if xyz<>"game" and xyz<>"people" and xyz<>"said":
            val = yield self.factory.conn.delete(xyz)

# ...

if __name__ == '__main__':
    from twisted.internet import reactor 
    conn = txredisapi.lazyRedisConnectionPool(reconnect = True)
    factory = STSFactory(conn)
    factory.clients = []

    print "Server started"
    reactor.listenTCP(11000,factory)
    reactor.listenTCP(11001,factory)
    reactor.listenTCP(11002,factory)
    reactor.run()

当我在Redis中使用大约725个键调用resetAll函数时,我遇到了异常。较低的数字,如200等,它不会被解雇。有人知道发生了什么吗?感谢。

1 个答案:

答案 0 :(得分:1)

在具有root访问权限的Linux / Mac计算机的终端上尝试此操作,并安装Python和Git:

cd
git clone https://github.com/andymccurdy/redis-py.git redis-py
cd redis-py
sudo python setup.py install
  

在幕后,redis-py使用连接池进行管理   连接到Redis服务器。默认情况下,每个Redis实例都是你   create将依次创建自己的连接池。你可以覆盖   此行为并通过传递使用现有连接池   已经为connection_pool创建了连接池实例   Redis课程的论点。

示例(将其另存为delkeys.py):

#!/usr/bin/python
import redis

pool = redis.ConnectionPool(host='localhost', port=6379, db=0)
r = redis.Redis(connection_pool=pool)
keys = r.keys()
for key in keys:
    if key<>"game" and key<>"people" and key<>"said":
        r.del(key)

请注意我没有经过测试的提醒,但您的评论可能会影响最终解决方案,或者您可以从这里开始。总是在redis-cli中进行监控以确定。