Rails: 4.2.5 Redis: 3.2.2 我们需要解决 Errno::ECONNREFUSED Redis::CannotConnectError 的问题
問題是什麼?
当触发时,应用程序会因无法连接到本地主机的Redis on localhost:6379(Errno::ECONNREFUSED)(Redis::CannotConnectError)而崩溃。
/path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:332:in `rescue in establish_connection': Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) (Redis::CannotConnectError)
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:318:in `establish_connection'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:94:in `block in connect'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:280:in `with_reconnect'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:93:in `connect'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:351:in `ensure_connected'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:208:in `block in process'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:293:in `logging'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:207:in `process'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis/client.rb:113:in `call'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:2085:in `block in publish'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:57:in `block in synchronize'
from /Users/hirokishirai/.rbenv/versions/2.3.0/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:57:in `synchronize'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/redis-3.2.2/lib/redis.rb:2084:in `publish'
from /path_to_app_dir/vendor/bundle/ruby/2.3.0/gems/websocket-rails-0.7.0/lib/websocket_rails/synchronization.rb:63:in `block in publish'
两个解决方案
两者都已经进行了操作确认。
您可以直接使用moaa的修复补丁,或者暂时将Redis降级至3.2.0版本,并等待websocket-rail的主分支合并修复补丁。我认为无论哪种方式都可以。
使用moaa/websocket-rails的sync_fixes分支的方法1
将Gemfile修改为以下内容
- gem 'websocket-rails'
+ gem 'websocket-rails', github: 'moaa/websocket-rails', branch: 'sync_fixes'
把方法2中的gem ‘redis’版本降级到3.2.0。
修改Gemfile内容如下
- gem 'redis'
+ gem 'redis', '3.2.0'
由于Gemfile.lock锁定了版本,应该无法通过bundle install更新redis。
bundle update redis
来源↓
请用中文将以下内容进行改写,只需提供一种选项:
Source↓
在发送两条不同的消息时发生了Redis错误 · 问题 #313 · websocket-rails/websocket-rails