数据库
首页 > 数据库> > python – Redis定期断开并重新连接Twisted

python – Redis定期断开并重新连接Twisted

作者:互联网

我有Twisted服务器与Redis的持续连接.
我正在使用库https://github.com/fiorix/txredisapi.

问题是Twisted不时失去与Redis的连接并在不久之后重新连接.我不知道为什么.
同样的事情发生在我的本地机器和我的在线VPS上.

日志:

2013-04-12 11:25:34+0200 [RedisProtocol,client] <twisted.internet.tcp.Connector instance at 0xf6c45d4c> will retry in 10 seconds
2013-04-12 11:25:34+0200 [RedisProtocol,client] Stopping factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>
2013-04-12 11:25:45+0200 [-] Starting factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>
2013-04-12 11:30:47+0200 [RedisProtocol,client] <twisted.internet.tcp.Connector instance at 0xf6c45d4c> will retry in 10 seconds
2013-04-12 11:30:47+0200 [RedisProtocol,client] Stopping factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>
2013-04-12 11:30:58+0200 [-] Starting factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>
2013-04-12 11:35:59+0200 [RedisProtocol,client] <twisted.internet.tcp.Connector instance at 0xf6c45d4c> will retry in 10 seconds
2013-04-12 11:35:59+0200 [RedisProtocol,client] Stopping factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>
2013-04-12 11:36:10+0200 [-] Starting factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>
2013-04-12 11:41:12+0200 [RedisProtocol,client] <twisted.internet.tcp.Connector instance at 0xf6c45d4c> will retry in 8 seconds
2013-04-12 11:41:12+0200 [RedisProtocol,client] Stopping factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>
2013-04-12 11:41:21+0200 [-] Starting factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>

它整天都在发生,我的日志很快变大了.

在redis断开连接时有人连接时记录:

2013-04-12 12:29:58+0200 [HTTPPageGetter,client] Unhandled error in Deferred:
2013-04-12 12:29:58+0200 [HTTPPageGetter,client] Unhandled Error
Traceback (most recent call last):
Failure: lib.txredisapi.txredisapi.ConnectionError: Not connected
2013-04-12 12:30:03+0200 [-] Starting factory <lib.txredisapi.txredisapi.RedisFactory instance at 0xf6c45ccc>
2013-04-12 12:30:22+0200 [Protocol,20,89.73.182.51] Connection from 89.73.182.51:38635 closed. Code: 1006, Reason: connection was closed uncleanly (peer dropped the TCP connection without previous WebSocket closing handshake)

解决方法:

好的,我从txredisapi的创建者那里得到了回答.在配置中有超时设置,默认设置为300秒.很简单.

标签:python,asynchronous,redis,twisted,disconnect
来源: https://codeday.me/bug/20190625/1284892.html