Permalink
Browse files

Merge pull request #19 from EmberAds/set-db-in-initialize

Allow the redis client instance to be passed in.
  • Loading branch information...
2 parents 6623fa7 + 9c8364e commit 78169ff91e956a0eb9e016312d53e19f37f3921d @igrigorik committed May 30, 2012
Showing with 15 additions and 2 deletions.
  1. +1 −1 lib/bloomfilter/counting_redis.rb
  2. +1 −1 lib/bloomfilter/redis.rb
  3. +7 −0 spec/counting_redis_spec.rb
  4. +6 −0 spec/redis_spec.rb
@@ -10,7 +10,7 @@ def initialize(opts = {})
:ttl => false,
:server => {}
}.merge opts
- @db = ::Redis.new(@opts[:server])
+ @db = @opts.delete(:db) || ::Redis.new(@opts[:server])
end
def insert(key, ttl=nil)
View
@@ -10,7 +10,7 @@ def initialize(opts = {})
:eager => false,
:server => {}
}.merge opts
- @db = ::Redis.new(@opts[:server])
+ @db = @opts.delete(:db) || ::Redis.new(@opts[:server])
if @opts[:eager]
@db.setbit @opts[:namespace], @opts[:size]+1, 1
@@ -52,5 +52,12 @@
it "should connect to remote redis server" do
lambda { CountingRedis.new }.should_not raise_error
end
+
+ it "should allow redis client instance to be passed in" do
+ redis_client = mock Redis
+ bf = BloomFilter::CountingRedis.new(:db => redis_client)
+ bf.instance_variable_get(:@db).should be == redis_client
+ end
+
end
end
View
@@ -46,6 +46,12 @@
lambda { BloomFilter::Redis.new }.should_not raise_error
end
+ it "should allow redis client instance to be passed in" do
+ redis_client = mock ::Redis
+ bf = BloomFilter::Redis.new(:db => redis_client)
+ bf.instance_variable_get(:@db).should be == redis_client
+ end
+
it "should allow namespaced BloomFilters" do
bf1 = BloomFilter::Redis.new(:namespace => :a)
bf2 = BloomFilter::Redis.new(:namespace => :b)

0 comments on commit 78169ff

Please sign in to comment.