2015-04-29 45 views
1

我試圖用彪馬在Heroku Redis的連接連接,但我一直運行到Ruby on Rails的 - 彪馬on_worker_boot與Redis的

Read error: #<Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)>

我搜索計算器,但答案沒有錯誤似乎解決了我的問題。

puma.rb配置

workers Integer(ENV['WEB_CONCURRENCY'] || 2) 
threads_count = Integer(ENV['MAX_THREADS'] || 5) 
threads threads_count, threads_count 

preload_app! 

rackup  DefaultRackup 
port  ENV['PORT']  || 3000 
environment ENV['RACK_ENV'] || 'development' 

on_worker_boot do 
    ActiveRecord::Base.establish_connection 

    Redis.current.client.reconnect 
    $redis = Redis.current 
end 

redis.rb初始化

$redis = Redis.new(:url => ENV["REDISCLOUD_URL"]) 

我檢查ENV["REDISCLOUD_URL"]redis://rediscloud:[email protected]:port

我想不出什麼我做錯了,這一切似乎是正確的給我

回答

4

我不得不設置配置VAR heroku config:set REDIS_PROVIDER=REDISCLOUD_URL

Puma.rb

workers Integer(ENV['WEB_CONCURRENCY'] || 2) 
threads_count = Integer(ENV['MAX_THREADS'] || 5) 
threads threads_count, threads_count 

preload_app! 

rackup  DefaultRackup 
port  ENV['PORT']  || 3000 
environment ENV['RACK_ENV'] || 'development' 

on_worker_boot do 
    ActiveRecord::Base.establish_connection 

    if ENV["REDISCLOUD_URL"] 
    uri = URI.parse(ENV["REDISCLOUD_URL"]) 
    Redis.current = Redis.new(host: uri.host, port: uri.port, password: uri.password) 
    $redis = Redis.current 
    else 
    Redis.current.quit 
    end 
end 

redis.rb

if ENV["REDISCLOUD_URL"] 
    uri = URI.parse(ENV["REDISCLOUD_URL"]) 
    $redis = Redis.new(host: uri.host, port: uri.port, password: uri.password) 
end 
+0

參考:https://github.com/mperham/sidekiq/wiki/Using-Redis#using-an -env可變 – rebagliatte