I'm trying to connect my rails application to a redis-to-go server with Resque but i'm gettin the error:
Error connecting to Redis on localhost:6379 (ECONNREFUSED)
I tried a lot of possible solutions but any of them worked. I follow all the instructions HERE but nothing.
I have 2 initializers:
redis.rb
ENV["REDISTOGO_URL"] ||= "redis://redistogo:[email protected]:9408/"
uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
resque.rb
Resque.redis = REDIS
Dir["#{Rails.root}/app/workers/*.rb"].each { |file| require file }
Resque.before_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
Resque.after_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
And the rake file:
require 'rake/dsl_definition'
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] ||= '*'
Resque.before_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
Resque.after_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.establish_connection
end
end
namespace :resque do
desc "let resque workers always load the rails environment"
task :setup => :environment do
ENV['QUEUE'] ||= '*'
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection }
end
desc "kill all workers (using -QUIT), god will take care of them"
task :stop_workers => :environment do
pids = Array.new
Resque.workers.each do |worker|
pids << worker.to_s.split(/:/).second
end
if pids.size > 0
system("kill -QUIT #{pids.join(' ')}")
end
# god should handle the restart
end
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
I added some code of a lot of parts so it's a little ugly right now, but before i tried to use redis-to-go i was using this locally with other configs and it works but now i want to deploy in heroku and the problems starts :c.
PS
If i try to do a manually insert/get to redis it works! (rails console)
irb(main):001:0> REDIS.set("foo", "bar")
=> "OK"
irb(main):002:0> REDIS.get("foo")
=> "bar"
try using the Redis.new(url: REDIS_URL) syntax rather than URI.parse