Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Allow the redis client instance to be passed in.

Saves having to rebuild the connection details hash to pass in as :server when you already have a redis instance in your ruby app. Pass in using :db option to BloomFilter::Redis.new or BloomFilter::CountingRedis.new.
  • Loading branch information...
commit 9c8364e4cea4e94c94ce6ea7f7c4dd8380ed9d00 1 parent a6b0218
@caius caius authored
View
2  lib/bloomfilter/counting_redis.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
2  lib/bloomfilter/redis.rb
@@ -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
View
7 spec/counting_redis_spec.rb
@@ -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
6 spec/redis_spec.rb
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.