title: Redis/Resque [Error connecting to Redis on localhost:6379 (ECONNREFUSED)]
body: <p>I'm trying to connect my rails application to a redis-to-go server with Resque but i'm gettin the error:</p>
  
  <pre><code>Error connecting to Redis on localhost:6379 (ECONNREFUSED)
  </code></pre>
  
  <p>I tried a lot of possible solutions but any of them worked. I follow all the instructions <a href="http://redistogo.com/documentation/resque?language=en" rel="nofollow">HERE</a> but nothing.</p>
  
  <p>I have 2 initializers:</p>
  
  <p><strong>redis.rb</strong></p>
  
  <pre><code>ENV["REDISTOGO_URL"] ||= "redis://redistogo:7d3dd2a11d0018445472de9d676360c3@albacore.redistogo.com:9408/"
  uri = URI.parse(ENV["REDISTOGO_URL"])
  REDIS = Redis.new(:host =&gt; uri.host, :port =&gt; uri.port, :password =&gt; uri.password)
  </code></pre>
  
  <p><strong>resque.rb</strong></p>
  
  <pre><code>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
  </code></pre>
  
  <p>And the rake file:</p>
  
  <pre><code>require 'rake/dsl_definition'
  require 'resque/tasks'
  
  
  task "resque:setup" =&gt; :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 =&gt; :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 =&gt; :environment do
      pids = Array.new
  
      Resque.workers.each do |worker|
        pids &lt;&lt; worker.to_s.split(/:/).second
      end
  
      if pids.size &gt; 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" =&gt; "resque:work"
  </code></pre>
  
  <p>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.</p>
  
  <p><strong>PS</strong></p>
  
  <p>If i try to do a manually insert/get to redis it works!
  (rails console)</p>
  
  <pre><code>irb(main):001:0&gt; REDIS.set("foo", "bar")
  =&gt; "OK"
  irb(main):002:0&gt; REDIS.get("foo")
  =&gt; "bar"
  </code></pre>