简体   繁体   English

Rails + Sidekiq:Redis 重置为空状态(sidekiq 历史丢失)

[英]Rails + Sidekiq: Redis getting reset to empty state (sidekiq history lost)

We have a Rails 6.1 app and using Sidekiq for bacground jobs.我们有一个 Rails 6.1 应用程序,并使用 Sidekiq 进行免费工作。 Sometimes it happens that the sidekiq web UI resets to the initial state, showing the completed/failed job counters near zero, indicating a recent Redis reset.有时,sidekiq Web UI 会重置为初始状态,显示完成/失败的作业计数器接近零,表明最近 Redis 重置。 What could be causing this?什么可能导致这种情况?

This was being caused by Rails using the same Redis as cache store and someone just ran Rails.cache.clear which in turns calls Redis command FLUSHDB which clears the whole DB.这是由 Rails 使用与缓存存储相同的 Redis 引起的,有人刚刚运行 Rails.cache.clear,后者又调用 Redis 命令 FLUSHDB 来清除整个数据库。

There are two possible solutions:有两种可能的解决方案:

  1. use separate Redis instance for Rails cache and Sidekiq workers (IMO overkill for most cases)为 Rails 缓存和 Sidekiq 工作人员使用单独的 Redis 实例(大多数情况下 IMO 矫枉过正)

  2. use separate Redis DB for Rails.cache and Sidekiq.为 Rails.cache 和 Sidekiq 使用单独的 Redis DB。 This still means that you need separare REDIS_URL config for Rails.cache and Sidekiq but you can just use different Redis DB (by default redis supports up to 16 separate DBs).这仍然意味着您需要为 Rails.cache 和 Sidekiq 设置单独的 REDIS_URL 配置,但您可以使用不同的 Redis DB(默认情况下 redis 最多支持 16 个单独的 DB)。 To do this set做这组

    REIDS_URL_RAILS=redis://host:10000/0 REIDS_URL_RAILS=redis://host:10000/0
    REIDS_URL_SIDEKIQ=redis://host:10000/1 REIDS_URL_SIDEKIQ=redis://host:10000/1

    And adjust your configs accordingly.并相应地调整您的配置。 The number at the end of the url is the ID of the database to use (by default DB=0 is used). url 末尾的数字是要使用的数据库的 ID(默认使用 DB=0)。

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

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