Sha256: eecf028809a2cbe8d6b5e5b2d60306b3e11c136e25d796818f8e1eb56512608b

Contents?: true

Size: 714 Bytes

Versions: 1

Compression:

Stored size: 714 Bytes

Contents

require 'connection_pool'
require 'redis'
require 'redis/namespace'

module Sidekiq
  class RedisConnection
    def self.create(options={})
      url = options[:url] || ENV['REDISTOGO_URL'] || 'redis://localhost:6379/0'
      # need a connection for Fetcher and Retry
      size = options[:size] || (Sidekiq.options[:concurrency] + 2)

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

    def self.build_client(url, namespace)
      client = Redis.connect(:url => url)
      if namespace
        Redis::Namespace.new(namespace, :redis => client)
      else
        client
      end
    end
    private_class_method :build_client
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sidekiq-0.11.2 lib/sidekiq/redis_connection.rb