2012-06-07 44 views
2

我一直是这样的错误挣扎了很长一段时间:Redis的连接在多线程环境(独角兽)

Redis::ProtocolError: Got 'i' as initial reply byte. 
If you're running in a multi-threaded environment, make sure you pass the :thread_safe 
option when initializing the connection. If you're in a forking environment, such as 
Unicorn, you need to connect to Redis after forking. 

它间歇发生在使用独角兽和Redis的应用程序。从这redis-rb Github issue它看起来:thread_safe选项现在默认启用。我正在使用redis 2.2.2,因为redis 3.0.1与最新版本的resque不兼容。

在我的独角兽配置中,我在分叉之后使用了Redis.current.quit

我还使用名为ruote-redis的gem连接到Redis,这是一个工作流引擎Ruote的存储实现。

如何确保我所有的Redis连接都稳定,并且不会再出现这个错误,这会影响我们应用的正常使用?

回答

2

独角兽不是多线程的。你自己在使用线程吗?

如文档中所述,您遇到的问题是多个独角兽工作人员共享相同的连接(即相同的基础文件描述符)。

This change,包含在版本redis-rb 3.0中,使其更加清晰。

如果您仍然遇到此错误,请发布您的独角兽配置。

+0

我没有使用线程。我很乐意使用redis-rb 3.0,但resque与它不兼容。我将'ruote-redis'宝石换成了'ruote-mon',它使用Mongo进行存储。这似乎解决了这个问题。 –