简体   繁体   English

Redis / Resque [在本地主机上连接到Redis时出错:6379(ECONNREFUSED)]

[英]Redis/Resque [Error connecting to Redis on localhost:6379 (ECONNREFUSED)]

I'm trying to connect my rails application to a redis-to-go server with Resque but i'm gettin the error: 我正在尝试使用Resque将Rails应用程序连接到Redis-to-go服务器,但出现错误:

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: 我有2个初始化器:

redis.rb 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.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: 和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"

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. 我添加了很多部分的代码,所以现在有点丑陋,但是在我尝试使用redis-to-go之前,我在本地将其与其他配置一起使用,并且可以正常工作,但是现在我想在heroku中进行部署并且存在问题开始:c。

PS PS

If i try to do a manually insert/get to redis it works! 如果我尝试手动插入/获取Redis,它会起作用! (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 尝试使用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.

相关问题 (在localhost:6379(Errno :: ECONNREFUSED)上连接到Redis时出错): - (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)): Rails-Redis :: CannotConnectError:在本地主机上连接Redis时出错:6379(Errno :: ECONNREFUSED) - Rails - Redis::CannotConnectError: Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED) Redis :: CannotConnectError(在localhost:6379(Errno :: ECONNREFUSED)上连接到Redis时出错): - Redis::CannotConnectError (Error connecting to Redis on localhost:6379 (Errno::ECONNREFUSED)): 将Resque-Scheduler与Docker-Compose结合使用-在本地主机上连接到Redis时出错:6379 - Using Resque-Scheduler with Docker-Compose - Error connecting to Redis on localhost:6379 在 127.0.0.1:6379 (Errno::ECONNREFUSED) 上连接到 Redis 时出错 - Wercker - Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) - Wercker rails + docker + sidekiq +错误连接到127.0.0.1:6379上的Redis(Errno :: ECONNREFUSED) - rails + docker + sidekiq + Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) 在 Rails 应用程序上的 127.0.0.1:6379(ECONNREFUSED) 上连接到 Redis 时出错 - Error connecting to Redis on 127.0.0.1:6379(ECONNREFUSED) on rails application 想在Heroku上使用Redis(Redis :: CannotConnectError(在127.0.0.1:6379上连接到Redis时出错(ECONNREFUSED))) - Want to use Redis on Heroku (Redis::CannotConnectError ( Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)) ) Sidekiq 在 docker-compose 上的 127.0.0.1:6379 (Errno::ECONNREFUSED) 上连接到 Redis 时出错 - Sidekiq Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED) on docker-compose GiLab CI-Redis :: CannotConnectError:在127.0.0.1:6379上连接到Redis时出错 - GiLab CI - Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM