Sha256: 3fd91fcad30206641d8c0fc5b0da91e4534ca8c02c6c1bd8eeb25579b9c501b8

Contents?: true

Size: 815 Bytes

Versions: 3

Compression:

Stored size: 815 Bytes

Contents

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

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

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
creeper-2.0.2 lib/creeper/redis_connection.rb
creeper-2.0.1 lib/creeper/redis_connection.rb
creeper-2.0.0 lib/creeper/redis_connection.rb