Permalink
Browse files

Allow configuring the redis connection

  • Loading branch information...
bkeepers committed Sep 21, 2011
1 parent d4eb9b9 commit 22411898c4d4598558149359b4091b69e06dada5
Showing with 35 additions and 3 deletions.
  1. +9 −2 lib/qu/backend/redis.rb
  2. +1 −1 qu-redis.gemspec
  3. +25 −0 spec/qu/backend/redis_spec.rb
View
@@ -1,11 +1,18 @@
-require 'redis'
+require 'redis-namespace'
require 'simple_uuid'
module Qu
module Backend
class Redis < Base
+ attr_accessor :namespace
+
+ def initialize
+ self.namespace = :qu
+ end
+
def redis
- @redis ||= ::Redis.connect
+ @redis ||= Qu.connection ||
+ ::Redis::Namespace.new(namespace, :redis => ::Redis.connect(:url => ENV['REDISTOGO_URL']))
end
def enqueue(klass, *args)
View
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.files = `git ls-files -- lib | grep redis`.split("\n")
s.require_paths = ["lib"]
- s.add_dependency 'redis'
+ s.add_dependency 'redis-namespace'
s.add_dependency 'simple_uuid'
s.add_dependency 'qu', Qu::VERSION
end
@@ -25,4 +25,29 @@
subject.redis.get("worker:#{worker.id}").should be_nil
end
end
+
+ describe 'connection' do
+ it 'should use the qu connection' do
+ Qu.connection = mock('a connection')
+ subject.redis.should == Qu.connection
+ end
+
+ it 'should create default connection if one not provided' do
+ subject.redis.client.host.should == '127.0.0.1'
+ subject.redis.client.port.should == 6379
+ subject.redis.namespace.should == :qu
+ end
+
+ it 'should use REDISTOGO_URL from heroku with namespace' do
+ ENV['REDISTOGO_URL'] = 'redis://0.0.0.0:9876'
+ subject.redis.client.host.should == '0.0.0.0'
+ subject.redis.client.port.should == 9876
+ subject.redis.namespace.should == :qu
+ end
+
+ it 'should allow customizing the namespace' do
+ subject.namespace = :foobar
+ subject.redis.namespace.should == :foobar
+ end
+ end
end

0 comments on commit 2241189

Please sign in to comment.