I am having unexpected and significant problems trying to get a Rails application running under Unicorn to connect to a password protected Redis server.
Using bundle exec rails c production
on the command line, I can issue commands through Resque.redis. However, it seems that my configuration is lost when it forks under Unicorn.
Using a Redis server without password protection Just Works. However, I intend to run workers on other servers than where the Redis server lives, so I need this to be password protected.
I also had success in using password protected (using the same method), but using Passenger rather than Unicorn.
I have the following setup:
# config/resque.yml development: localhost:6379 test: localhost:6379 production: redis:
.
# 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
.
source share