Sha256: 2c23b01b26f5840fe9b2f26f3a38579cd407b43cc77b0bc1cd6783eba8e0fb67

Contents?: true

Size: 903 Bytes

Versions: 12

Compression:

Stored size: 903 Bytes

Contents

# Set and access +Resque.redis+ in a thread-safe way.
module Resque::ThreadSafeRedis
  thread_mattr_accessor :thread_resque_override

  def self.resque_override
    self.thread_resque_override ||= ResqueOverride.new
  end

  def redis
    Resque::ThreadSafeRedis.resque_override.data_store_override || super
  end
  alias :data_store :redis

  def with_per_thread_redis_override(redis_instance, &block)
    Resque::ThreadSafeRedis.resque_override.enable_with(redis_instance, &block)
  end

  class ResqueOverride
    include Resque

    attr_accessor :data_store_override

    def enable_with(server, &block)
      previous_redis, previous_data_store_override = redis, data_store_override
      self.redis = server
      self.data_store_override = @data_store

      block.call
    ensure
      self.redis = previous_redis
      self.data_store_override = previous_data_store_override
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
mission_control-jobs-0.6.0 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.5.0 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.4.0 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.3.3 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.3.2 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.3.1 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.3.0 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.2.2 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.2.1 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.2.0 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.1.1 lib/resque/thread_safe_redis.rb
mission_control-jobs-0.1.0 lib/resque/thread_safe_redis.rb