简体   繁体   中英

Default Sidekiq Redis configuration in Rails app

I'm trying to understand the Redis & Sidekiq configuration in a Passenger+Rails app and have run into some lack of understanding. I start the redis server independently of my rails app, while Sidekiq is a gem in my Rails app. I start it likewise: (no sidekiq.yml file needed for me)

bundle exec sidekiq

Following is my sidekiq.rb initializer:

require 'sidekiq'
require 'sidekiq-status'

Sidekiq.configure_client do |config|
  config.client_middleware do |chain|
    chain.add Sidekiq::Status::ClientMiddleware
  end
end

Sidekiq.configure_server do |config|
  config.server_middleware do |chain|
    chain.add Sidekiq::Status::ServerMiddleware, expiration: 30.minutes
  end
  config.client_middleware do |chain|
    chain.add Sidekiq::Status::ClientMiddleware
  end
end

I went through some library classes, but to no avail.

I want to understand where does Sidekiq configure it's Redis server details. It defaults to localhost:6379 , but I am not quite sure how.
Also, if I wish to use Memcached in future, how can I change that?

From sidekiq docs:

By default, Sidekiq tries to connect to Redis at localhost:6379

https://github.com/mperham/sidekiq/wiki/Using-Redis

You can change the port in the initializer:

 Sidekiq.configure_server do |config|
      config.redis = { url: 'redis://redis.example.com:7372/12' }
 end

From the looks of it sidekiq works only with redis

Sidekiq uses Redis to store all of its job and operational data.

这是我从另一个答案中所做的:

# frozen_string_literal: true
Sidekiq.configure_server do |config|
  config.redis = {
    url: ENV.fetch("SIDEKIQ_REDIS_URL", "redis://localhost:6379/1")
  }
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM