使用Sidekiq(Resuqe的多线程版本)来设置Redis的连接地址

我迷上了 Sidekiq,但是 Redis 并不是大多数情况下都是 localhost:6379 的呢,嗯。

在Sidekiq的Advanced Options中,如果是Unicorn的情况,有写着在unicorn.rb的after_fork里写configure_client的代码块,所以只有在那里写的时候才能正常运行。

不,它是可以动的,但是它默认连接到localhost:6379。所以,

Sidekiq.configure_server do |config|
  config.redis = { :url => $redis_host , :namespace => 'resque'}
end

# When in Unicorn, this block needs to go in unicorn's `after_fork` callback:
Sidekiq.configure_client do |config|
  config.redis = { :url => $redis_host , :namespace => 'resque'}
end
after_fork do |server, worker|
  defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection

  # When in Unicorn, this block needs to go in unicorn's `after_fork` callback:
  Sidekiq.configure_client do |config|
    config.redis = { :url => redis_host , :namespace => 'resque'}
  end
end

如果不在两边都写的话,事情就无法顺利进行了。嗯,尽管从Runner向队列加入这种情况较为异常。