1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00
mperham--sidekiq/lib/sidekiq/redis_connection.rb
Mike Perham f89eedf326 Add new sidekiq/testing feature.
This makes job processing synchronous when required.
2012-02-09 21:46:44 -08:00

39 lines
694 B
Ruby

require 'connection_pool'
require 'redis/namespace'
module Sidekiq
class RedisConnection
def self.create(url=nil, namespace=nil, pool=true)
@namespace = namespace
@url = url
if pool
ConnectionPool.new { connect }
else
connect
end
end
def self.connect
if namespace
Redis::Namespace.new(namespace, :redis => redis_connection)
else
redis_connection
end
end
def self.namespace
@namespace
end
def self.url
@url || ENV['REDISTOGO_URL'] || 'redis://localhost:6379/0'
end
private
def self.redis_connection
Redis.connect(:url => url)
end
end
end