Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to Redis server in Windows 10 ruby on rails

I am having trouble connecting to Redis in my rails app on windows 10, and I added Redis to my gem file and setup my cable.yml file. The error that I am getting when I start my rails server is rescue in establish_connection': Timed out connecting to Redis on localhost:6379 how do I fix this problem.

cable.yml

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

test:
  adapter: async

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

commandline

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>
like image 573
jmike Avatar asked Oct 18 '22 10:10

jmike


1 Answers

Well, I had the same issue and it's working for me with this cable.ymlconfig:

development:
  adapter: async

The crazy thing is that it's actually connecting to my local redis server! I guess that it shouldn't use redis at all with that config, but it's using it and it's working just fine.

Instead, if I set what I thought it was the correct configuration, it fails:

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

This is the error:

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)

So, I'm not sure why, and would be great if someone can explain it, but with adapter: async it's solved for me (Rails 5.0.7, Windows 10, redis gem 3.3.3).

like image 74
fsinisi90 Avatar answered Oct 19 '22 23:10

fsinisi90