2012-02-08 16:43:57 -06:00
|
|
|
require 'connection_pool'
|
|
|
|
require 'redis/namespace'
|
|
|
|
|
|
|
|
module Sidekiq
|
|
|
|
class RedisConnection
|
|
|
|
def self.create(url = nil, namespace = nil, pool = true)
|
2012-02-09 09:37:00 -06:00
|
|
|
@namespace = namespace ? namespace : nil
|
2012-02-09 09:31:32 -06:00
|
|
|
@url = url ? url : nil
|
2012-02-09 09:37:00 -06:00
|
|
|
|
2012-02-08 16:43:57 -06:00
|
|
|
if pool
|
|
|
|
ConnectionPool.new { connect }
|
|
|
|
else
|
|
|
|
connect
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.connect
|
|
|
|
r = Redis.connect(:url => url)
|
2012-02-09 09:39:27 -06:00
|
|
|
|
2012-02-08 16:43:57 -06:00
|
|
|
if namespace
|
|
|
|
Redis::Namespace.new(namespace, :redis => r)
|
|
|
|
else
|
|
|
|
r
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.namespace
|
2012-02-09 09:37:00 -06:00
|
|
|
@namespace
|
2012-02-08 16:43:57 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.url
|
2012-02-09 09:31:32 -06:00
|
|
|
@url || ENV['REDISTOGO_URL'] || 'redis://localhost:6379/0'
|
2012-02-08 16:43:57 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|