Resque, Resque Server, on RedisToGo with Heroku

后端 未结 1 749
旧巷少年郎
旧巷少年郎 2021-02-15 16:42

I\'ve been trying to get Resque (with Resque server) & RedisToGo working on heroku (cedar) for awhile now, but I keep running into this error:

Redis::CannotC         


        
1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-15 17:11

    I think your Procfile has a typo. Why do you have two web processes? I'd stick with one and use unicorn.

    web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb

    When using unicorn with resque, you have to define the resque redis connection each time unicorn forks. Here are the relevant files.

    config/initializers/redis.rb

    uri = URI.parse(ENV["REDIS_WORKER"])
    REDIS_WORKER = Redis.new(host: uri.host, port: uri.port, password: uri.password)
    

    config/initializers/resque.rb

    Resque.redis = REDIS_WORKER
    

    config/unicorn.rb

    before_fork do |server, worker|
      if defined?(Resque)
        Resque.redis.quit
        Rails.logger.info("Disconnected from Redis")
      end
    end
    
    after_fork do |server, worker|
      if defined?(Resque)
        Resque.redis = REDIS_WORKER
        Rails.logger.info("Connected to Redis")
      end
    end
    

    See this gist for the complete unicorn.rb

    0 讨论(0)
提交回复
热议问题