在heroku中使用redis实现react和rails api

vsdwdz23  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(413)

我在heroku上部署了一个railsapi,它用于react.js静态页面。它们都部署在heroku上,并通过api链接进行通信。我在使用redis和sidekiq时遇到了麻烦。
在我的railsapi上,我配置了redistogo链接,没有任何问题,但是当我转到我的react应用程序并尝试发送电子邮件邀请时,我收到了这个消息 Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED) . 我想,如果我有它配置在我的后端然后它将工作到我的静态页面应用程序。
锡德基

---
:verbose: false
:concurrency: 3
staging:
  :concurrency: 1
production:
  :concurrency: 5
:queues:
  - [mailers,2]
  - slack_notifications
  - mixpanel
  - invoices
  - default
  - rollbar

redis.rb版

uri = URI.parse(ENV["REDISTOGO_URL"])
REDIS = Redis.new(:url => uri)

sidekiq.rb公司

Sidekiq::Extensions.enable_delay!

unless Rails.env == 'development' || Rails.env == 'test'
  Sidekiq.configure_server do |config|
    config.redis = {
      url: Rails.application.credentials.redis_url,
      password: Rails.application.credentials.redis_password
    }
  end

  Sidekiq.configure_client do |config|
    config.redis = {
      url: Rails.application.credentials.redis_url,
      password: Rails.application.credentials.redis_password
    }
  end
end

# Turn off backtrace if at all memory issues are popping up as

# backtrace occupies to much memory on redis

# number of lines of backtrace and number of re-tries

Sidekiq.default_worker_options = { backtrace: false, retry: 3 }

Sidekiq.configure_server do |config|
  # runs after your app has finished initializing
  # but before any jobs are dispatched.
  config.on(:startup) do
    puts 'Sidekiq is starting...'
    # make_some_singleton
  end
  config.on(:quiet) do
    puts 'Got USR1, stopping further job processing...'
  end
  config.on(:shutdown) do
    puts 'Got TERM, shutting down process...'
    # stop_the_world
  end
end

所以我的问题是下一个:如果我已经在我的rails应用程序上配置了redistogo\u链接,那么我的react config vars上是否需要同样的链接?
在heroku中使用react作为前端,在railsapi上配置sidekiq和redis的最佳方法是什么?我还没在网上看到什么能报道这件事。
我会感激你的帮助!;)

1qczuiv0

1qczuiv01#

你得跑了 heroku config:set REDIS_PROVIDER=REDISTOGO_URL 告诉sidekiq使用reditogo\u url连接到redis。
https://github.com/mperham/sidekiq/wiki/using-redis#using-环境变量

相关问题