6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sidekiq(Resuqeのmulti threading版)でRedisの接続先を設定すっとき

Posted at

Sidekiq大好きになっちゃったんですが、
Redisってほとんどの場合、localhost:6379じゃないですよね、うん。

Sidekiq > Advanced OptionsにはUnicornの場合、configure_clientのブロックをunicorn.rbのafter_forkに書けって書いてあるんで、そっちにしか書いてないとRunnerんとき動かない。

いや、動くんだけど、デフォルトのlocalhost:6379にいくんで。
なので、

initializers/sidekiq.rb
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
unicorn.rb
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からenqueueするってシチュエーションの方がイレギュラーな気もしますが。

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?