ruby-on-rails – 连接到窗口10 ruby​​ on rails上的redis服务器

我在
Windows 10上的rails应用程序中连接到redis时遇到问题,我将redis添加到我的gem文件并设置了我的cable.yml文件.当我启动我的rails服务器时我得到的错误是在establish_connection中进行救援’:超时连接到localhost上的Redis:6379如何解决此问题.

cable.yml

development:
  adapter: redis
  url: redis://localhost:6379/1

test:
  adapter: async

production:
  adapter: redis
  url: redis://localhost:6379/1

命令行

C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:318:in `rescue in establish_connection': Timed out connecting to Redis on localhost:6379 (Redis::CannotConnectError)
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:311:in `establish_connection'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:91:in `block in connect'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:273:in `with_reconnect'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:90:in `connect'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:256:in `with_socket_timeout'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:267:in `without_socket_timeout'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:122:in `call_loop'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/subscribe.rb:35:in `subscription'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/subscribe.rb:12:in `subscribe'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:2587:in `_subscription'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:2008:in `block in subscribe'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:37:in `block in synchronize'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:37:in `synchronize'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:2007:in `subscribe'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actioncable-5.0.3/lib/action_cable/subscription_adapter/redis.rb:75:in `block in listen'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis/client.rb:273:in `with_reconnect'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:43:in `block in with_reconnect'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:37:in `block in synchronize'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:37:in `synchronize'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:42:in `with_reconnect'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/redis-3.2.0/lib/redis.rb:49:in `without_reconnect'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actioncable-5.0.3/lib/action_cable/subscription_adapter/redis.rb:72:in `listen'
        from C:/RailsInstaller/Ruby2.2.0/lib/ruby/gems/2.2.0/gems/actioncable-5.0.3/lib/action_cable/subscription_adapter/redis.rb:146:in `block in ensure_listener_running'

C:\Users\Michael\Desktop\ruby\chat>

最佳答案 好吧,我遇到了同样的问题,这对我来说是有用的.linelymlconfig:

development:
  adapter: async

疯狂的是,它实际上连接到我的本地redis服务器!我想它不应该在配置中使用redis,但它正在使用它并且它工作得很好.

相反,如果我设置我认为正确的配置,它会失败:

development:
  :adapter: redis
  :url: redis://localhost:6379/

这是错误:

C:/RailsInstaller/Ruby2.3.0/lib/ruby/gems/2.3.0/gems/redis-3.3.3/lib/redis/client.rb:345:in `rescue in establish_connection’: Error connecting to Redis on localhost:6379 (Redis::TimeoutError) (Redis::CannotConnectError)

所以,我不知道为什么,如果有人可以解释它会很棒,但是使用适配器:async它为我解决了(Rails 5.0.7,Windows 10,redis gem 3.3.3).

点赞