简体   繁体   English

Rails 应用程序中的默认 Sidekiq Redis 配置

[英]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.我正在尝试了解 Passenger+Rails 应用程序中的 Redis 和 Sidekiq 配置,但遇到了一些缺乏理解的问题。 I start the redis server independently of my rails app, while Sidekiq is a gem in my Rails app.我独立于我的 Rails 应用程序启动 redis 服务器,而 Sidekiq 是我的 Rails 应用程序中的一个宝石。 I start it likewise: (no sidekiq.yml file needed for me)我同样开始它:(我不需要 sidekiq.yml 文件)

bundle exec sidekiq捆绑执行 sidekiq

Following is my sidekiq.rb initializer:以下是我的 sidekiq.rb 初始化程序:

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.我想了解 Sidekiq 在哪里配置它的 Redis 服务器详细信息。 It defaults to localhost:6379 , but I am not quite sure how.它默认为localhost:6379 ,但我不太确定如何。
Also, if I wish to use Memcached in future, how can I change that?另外,如果我希望将来使用 Memcached,我该如何更改呢?

From sidekiq docs: 从sidekiq文档:

By default, Sidekiq tries to connect to Redis at localhost:6379 默认情况下,Sidekiq尝试通过localhost:6379连接到Redis

https://github.com/mperham/sidekiq/wiki/Using-Redis 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仅适用于redis

Sidekiq uses Redis to store all of its job and operational data. Sidekiq使用Redis存储其所有作业和运营数据。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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