Sha256: fac4ce26fdf1361e327b6a446c9fbcca48175eb39690fc7aea9e1c74d7033249

Contents?: true

Size: 1.43 KB

Versions: 11

Compression:

Stored size: 1.43 KB

Contents

require 'connection_pool'
require 'redis'

module Sidekiq
  class RedisConnection
    class << self

      def create(options={})
        url = options[:url] || determine_redis_provider || 'redis://localhost:6379/0'
        # need a connection for Fetcher and Retry
        size = options[:size] || (Sidekiq.server? ? (Sidekiq.options[:concurrency] + 2) : 5)

        log_info(url, options)

        ConnectionPool.new(:timeout => 1, :size => size) do
          build_client(url, options[:namespace], options[:driver] || 'ruby')
        end
      end

      private

      def build_client(url, namespace, driver)
        client = Redis.connect(:url => url, :driver => driver)
        if namespace
          require 'redis/namespace'
          Redis::Namespace.new(namespace, :redis => client)
        else
          client
        end
      end

      def log_info(url, options)
        opts = options.dup
        opts.delete(:url)
        if Sidekiq.server?
          Sidekiq.logger.info("Booting #{Sidekiq::NAME} #{Sidekiq::VERSION} using #{url} with options #{opts}")
        else
          Sidekiq.logger.info("#{Sidekiq::NAME} client using #{url} with options #{opts}")
        end
      end

      def determine_redis_provider
        # REDISTOGO_URL is only support for legacy reasons
        return ENV['REDISTOGO_URL'] if ENV['REDISTOGO_URL']
        provider = ENV['REDIS_PROVIDER'] || 'REDIS_URL'
        ENV[provider]
      end

    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
sidekiq-2.13.0 lib/sidekiq/redis_connection.rb
sidekiq-2.12.4 lib/sidekiq/redis_connection.rb
sidekiq-2.12.3 lib/sidekiq/redis_connection.rb
sidekiq-2.12.1 lib/sidekiq/redis_connection.rb
sidekiq-2.12.0 lib/sidekiq/redis_connection.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/redis_connection.rb
sidekiq-statsd-0.1.0 vendor/ruby/1.9.1/gems/sidekiq-2.11.2/lib/sidekiq/redis_connection.rb
sidekiq-2.11.2 lib/sidekiq/redis_connection.rb
sidekiq-2.11.1 lib/sidekiq/redis_connection.rb
sidekiq-2.11.0 lib/sidekiq/redis_connection.rb
sidekiq-2.10.1 lib/sidekiq/redis_connection.rb