python - Txredisapi异常.RuntimeError : maximum recursion depth exceeded

标签 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 等较低的数字,它不会被解雇。任何人都知道发生了什么事?谢谢。

最佳答案

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

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

Behind the scenes, redis-py uses a connection pool to manage connections to a Redis server. By default, each Redis instance you create will in turn create its own connection pool. You can override this behavior and use an existing connection pool by passing an already created connection pool instance to the connection_pool argument of the Redis class.

例子(保存为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 中进行监控以确保安全。

关于python - Txredisapi异常.RuntimeError : maximum recursion depth exceeded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9100208/

相关文章:

python - python中字符串的if语句?

python - 为什么我会收到有关 String not defined 的错误消息?

python - 如何为通过 socksipy 发出请求的 scrapy 编写 DownloadHandler?

python - 在 Twisted 中将消息从一台服务器发送到另一台服务器

python - 用于 MT 的 Jasmin HttpConnector

python - Pandas 列提取

python - 提取 DOCX 注释

python - 将 python flask 应用程序上下文传递给 rq 作业的正确方法

redis - 无法在redis中执行批量插入

python - Django 发出 IPC 信号