Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the redis client instance to be passed in. #19

Merged
merged 1 commit into from
May 30, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bloomfilter/counting_redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/bloomfilter/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/counting_redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions spec/redis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down