[英](Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)):
[英]Redis/Resque [Error connecting to Redis on localhost:6379 (ECONNREFUSED)]
我正在嘗試使用Resque將Rails應用程序連接到Redis-to-go服務器,但出現錯誤:
Error connecting to Redis on localhost:6379 (ECONNREFUSED)
我嘗試了很多可能的解決方案,但是其中任何一個都有效。 我在這里遵循所有指示,但什么也沒有。
我有2個初始化器:
redis.rb
ENV["REDISTOGO_URL"] ||= "redis://redistogo:7d3dd2a11d0018445472de9d676360c3@albacore.redistogo.com: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
和rake文件:
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"
我添加了很多部分的代碼,所以現在有點丑陋,但是在我嘗試使用redis-to-go之前,我在本地將其與其他配置一起使用,並且可以正常工作,但是現在我想在heroku中進行部署並且存在問題開始:c。
PS
如果我嘗試手動插入/獲取Redis,它會起作用! (導軌控制台)
irb(main):001:0> REDIS.set("foo", "bar")
=> "OK"
irb(main):002:0> REDIS.get("foo")
=> "bar"
嘗試使用Redis.new(url:REDIS_URL)語法而不是URI.parse
if Rails.env == 'production'
$redis = Redis.new(url: ENV["REDISCLOUD_URL"])
else
$redis = Redis.new
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.