How to tell if sidekiq is connected to redis server?

keruilin picture keruilin · Apr 5, 2013 · Viewed 8.9k times · Source

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

Answer

iltempo picture iltempo · Apr 6, 2013

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.