在 Windows 10 ruby​​ on Rails 中连接到 Redis 服务器

jmi*_*ike 5 ruby-on-rails redis

我在 Windows 10 上的 Rails 应用程序中连接到 Redis 时遇到问题,我将 Redis 添加到了 gem 文件中并设置了 Cable.yml 文件。当我启动 Rails 服务器时遇到的错误是rescue in establish_connection': Timed out connecting to Redis on localhost:6379如何解决这个问题。

电缆.yml

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

test:
  adapter: async

production:
  adapter: redis
  url: redis://localhost:6379/1
Run Code Online (Sandbox Code Playgroud)

命令行

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>
Run Code Online (Sandbox Code Playgroud)

fsi*_*i90 3

好吧,我遇到了同样的问题,并且它对我来说适用于以下cable.yml 配置:

development:
  adapter: async
Run Code Online (Sandbox Code Playgroud)

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

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

development:
  :adapter: redis
  :url: redis://localhost:6379/
Run Code Online (Sandbox Code Playgroud)

这是错误:

C:/RailsInstaller/Ruby2.3.​​0/lib/ruby/gems/2.3.0/gems/redis-3.3.3/lib/redis/client.rb:345:in `rescue in acquire_connection': 连接到本地主机上的 Redis 时出错:6379 (Redis::超时错误) (Redis::无法连接错误)

所以,我不确定为什么,如果有人可以解释它,但为我解决它,那就太好了adapter: async(Rails 5.0.7,Windows 10,redis gem 3.3.3)。