title: Rescuing Redis Exception in Rails
body: <p>I currently have a <code>Rails 3.2.13</code> app using <code>redis</code> as its <code>cache_store</code> and for <code>Sidekiq</code>. </p>
  
  <p>I'm also using redis master-slave. I ran into an issue where during failover a slave would be in the process of becoming master, Rails then connected to this node and once it tried to write to the node, even though the node was <code>master</code>, this exception was raised:</p>
  
  <pre><code>Redis::CommandError: READONLY You can't write against a read only slave.
  vendor/bundle/ruby/1.9.1/gems/redis-3.0.4/lib/redis/client.rb:85:in `call'
  vendor/bundle/ruby/1.9.1/gems/redis-3.0.4/lib/redis.rb:1181:in `block in srem'
  vendor/bundle/ruby/1.9.1/gems/redis-3.0.4/lib/redis.rb:36:in `block in synchronize'
  /usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
  vendor/bundle/ruby/1.9.1/gems/redis-3.0.4/lib/redis.rb:36:in `synchronize'
  vendor/bundle/ruby/1.9.1/gems/redis-3.0.4/lib/redis.rb:1180:in `srem'
  vendor/bundle/ruby/1.9.1/gems/redis-namespace-1.3.0/lib/redis/namespace.rb:306:in `method_missing'
  vendor/bundle/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/manager.rb:123:in `block in clear_worker_set'
  vendor/bundle/ruby/1.9.1/gems/connection_pool-1.0.0/lib/connection_pool.rb:48:in `with'
  vendor/bundle/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq.rb:67:in `redis'
  vendor/bundle/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/manager.rb:118:in `clear_worker_set'
  vendor/bundle/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/manager.rb:45:in `block in stop'
  vendor/bundle/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/util.rb:15:in `watchdog'
  vendor/bundle/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/manager.rb:33:in `stop'
  vendor/bundle/ruby/1.9.1/gems/celluloid-0.14.0/lib/celluloid/calls.rb:25:in `public_send'
  vendor/bundle/ruby/1.9.1/gems/celluloid-0.14.0/lib/celluloid/calls.rb:25:in `dispatch'
  vendor/bundle/ruby/1.9.1/gems/celluloid-0.14.0/lib/celluloid/calls.rb:125:in `dispatch'
  vendor/bundle/ruby/1.9.1/gems/celluloid-0.14.0/lib/celluloid/actor.rb:328:in `block in handle_message'
  vendor/bundle/ruby/1.9.1/gems/celluloid-0.14.0/lib/celluloid/tasks.rb:42:in `block in initialize'
  vendor/bundle/ruby/1.9.1/gems/celluloid-0.14.0/lib/celluloid/tasks/task_fiber.rb:9:in `block in create'
  </code></pre>
  
  <p>I know the issue could easily be resolved by disconnecting anything that's using redis (e.g. <code>sidekiq</code>, rails cache_store) so that any subsequent commands that write to that node would reconnect with a valid connection. </p>
  
  <p>The issue is where to catch and handle the exception? My initial thought was to do an <code>airbrake</code> kind of global rescue but not sure if that would be the best way to go about it. </p>
  
  <p>Has anyone run into this issue?</p>