[英](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.