Honza
Honza

Reputation: 4409

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

We have a Rails 6.1 app and using Sidekiq for bacground jobs. 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. What could be causing this?

Upvotes: 1

Views: 724

Answers (1)

Honza
Honza

Reputation: 4409

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.

There are two possible solutions:

  1. use separate Redis instance for Rails cache and Sidekiq workers (IMO overkill for most cases)

  2. use separate Redis DB for Rails.cache and Sidekiq. 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). To do this set

    REIDS_URL_RAILS=redis://host:10000/0
    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).

Upvotes: 2

Related Questions