gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 11:23:00 25 4
gpt4 key购买 nike

我正在尝试删除 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com