Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if sidekiq is connected to redis server?

Using the console, how can I tell if sidekiq is connected to a redis server? I want to be able to do something like this:

if (sidekiq is connected to redis) # psuedo code
  MrWorker.perform_async('do_work', user.id)
else
  MrWorker.new.perform('do_work', user.id)
end
like image 800
keruilin Avatar asked Apr 05 '13 21:04

keruilin


People also ask

How does Sidekiq use Redis?

Sidekiq uses simple and efficient background processing. Sidekiq is supported by Redis as a job management tool to process thousands of jobs in a second. Follow the steps to add Sidekiq and Redis to your existing application. Note: Redis gem is also installed in sidekiq, you don't have to install it independently.

How many Redis connections does Sidekiq use?

Note: Sidekiq needs 2 connections by default for a bunch of stuff like a heartbeat, maintain sentinel, etc.

What does Sidekiq store in Redis?

The only thing that sidekiq stores are what you've printed out as "Retrying Job info:". The long version... how does that work? along with other information sidekiq needs (the queue it should be run on and the retry count).

What is Sidekiq and Redis in Rails?

Sidekiq is one of the more widely used background job frameworks that you can implement in a Rails application. It is backed by Redis, an in-memory key-value store known for its flexibility and performance. Sidekiq uses Redis as a job management store to process thousands of jobs per second.


2 Answers

You can use Redis info provided by Sidekiq:

redis_info = Sidekiq.redis { |conn| conn.info }
redis_info['connected_clients'] # => "16"

Took it from Sidekiq's Sinatra status app.

like image 63
iltempo Avatar answered Oct 04 '22 02:10

iltempo


I make this method to Rails whit the obove answer, return true if connected and false if not.

  def redis_connected?
    !!Sidekiq.redis(&:info) rescue false
  end
like image 20
overallduka Avatar answered Oct 04 '22 03:10

overallduka