2012-02-08 16:43:57 -06:00
|
|
|
require 'connection_pool'
|
|
|
|
require 'redis/namespace'
|
|
|
|
|
|
|
|
module Sidekiq
|
|
|
|
class RedisConnection
|
2012-02-09 22:03:05 -08:00
|
|
|
<<<<<<< HEAD
|
2012-02-09 22:00:40 -08:00
|
|
|
def self.create(options={})
|
|
|
|
url = options[:url] || ENV['REDISTOGO_URL'] || 'redis://localhost:6379/0'
|
|
|
|
client = build_client(url, options[:namespace])
|
|
|
|
return ConnectionPool.new { client } if options[:use_pool]
|
|
|
|
client
|
2012-02-09 22:03:05 -08:00
|
|
|
=======
|
2012-02-09 21:46:44 -08:00
|
|
|
def self.create(url=nil, namespace=nil, pool=true)
|
|
|
|
@namespace = namespace
|
|
|
|
@url = url
|
2012-02-09 09:37:00 -06:00
|
|
|
|
2012-02-08 16:43:57 -06:00
|
|
|
if pool
|
|
|
|
ConnectionPool.new { connect }
|
|
|
|
else
|
|
|
|
connect
|
|
|
|
end
|
2012-02-09 22:03:05 -08:00
|
|
|
>>>>>>> c2877d690fac59ee18006912aeecd3babb072dc1
|
2012-02-08 16:43:57 -06:00
|
|
|
end
|
|
|
|
|
2012-02-09 22:00:40 -08:00
|
|
|
def self.build_client(url, namespace)
|
|
|
|
client = Redis.connect(:url => url)
|
2012-02-08 16:43:57 -06:00
|
|
|
if namespace
|
2012-02-09 22:00:40 -08:00
|
|
|
Redis::Namespace.new(namespace, :redis => client)
|
2012-02-08 16:43:57 -06:00
|
|
|
else
|
2012-02-09 22:00:40 -08:00
|
|
|
client
|
2012-02-08 16:43:57 -06:00
|
|
|
end
|
|
|
|
end
|
2012-02-09 22:00:40 -08:00
|
|
|
private_class_method :build_client
|
2012-02-08 16:43:57 -06:00
|
|
|
end
|
|
|
|
end
|