パスワードで保護されたRedisサーバーに接続するために、Unicornで実行されているRailsアプリを取得しようとすると、予期しない重大な問題が発生します。
コマンドラインで使用bundle exec rails c production
すると、Resque.redisを介してコマンドを発行できます。ただし、Unicornでフォークすると、構成が失われているようです。
パスワードで保護されていないRedisサーバーを使用するだけで機能します。ただし、Redisサーバーが存在する場所以外のサーバーでワーカーを実行するつもりなので、パスワードで保護する必要があります。
また、パスワードで保護された(同じ手法を使用して)が、UnicornではなくPassengerを使用することに成功しました。
私は次の設定をしています:
# config/resque.yml
development: localhost:6379
test: localhost:6379
production: redis://user:PASSWORD@oak.isc.org:6379
。
# config/initializers/redis.rb
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
rails_env = ENV['RAILS_ENV'] || 'development'
$resque_config = YAML.load_file(rails_root + '/config/resque.yml')
uri = URI.parse($resque_config[rails_env])
Resque.redis = Redis.new(host: uri.host, port: uri.port, password: uri.password)
。
# unicorn.rb bootup file
preload_app true
before_fork do |server, worker|
Redis.current.quit
end
after_fork do |server, worker|
Redis.current.quit
end
。