redis-bloomfilter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -85,7 +85,7 @@ The lua version is about ~3 times faster than the pure-Ruby version
85
85
 
86
86
  Lua code is taken from https://github.com/ErikDubbelboer/redis-lua-scaling-bloom-filter
87
87
 
88
- 1.000.000 ~= 1.5Mb occuped on Redis
88
+ 1.000.000 ~= 1.5Mb occupied on Redis
89
89
 
90
90
  Contributing to redis-bloomfilter
91
91
  ----------------
@@ -1,7 +1,7 @@
1
1
  class Redis
2
2
  class Bloomfilter
3
3
 
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
 
6
6
  def self.version
7
7
  "redis-bloomfilter version #{VERSION}"
@@ -19,7 +19,7 @@ class Redis
19
19
  :key_name => 'redis-bloomfilter',
20
20
  :hash_engine => 'md5',
21
21
  :redis => Redis.current,
22
- :driver => 'ruby'
22
+ :driver => nil
23
23
  }.merge options
24
24
 
25
25
  raise ArgumentError, "options[:size] && options[:error_rate] cannot be nil" if options[:error_rate].nil? || options[:size].nil?
@@ -33,6 +33,17 @@ class Redis
33
33
 
34
34
  @redis = @options[:redis] || Redis.current
35
35
  @options[:hash_engine] = options[:hash_engine] if options[:hash_engine]
36
+
37
+ if @options[:driver].nil?
38
+ ver = @redis.info['redis_version']
39
+
40
+ if Gem::Version.new(ver) >= Gem::Version.new('2.6.0')
41
+ @options[:driver] = 'lua'
42
+ else
43
+ @options[:driver] = 'ruby'
44
+ end
45
+ end
46
+
36
47
  driver_class = Redis::BloomfilterDriver.const_get(driver_name)
37
48
  @driver = driver_class.new @options
38
49
  @driver.redis = @redis
@@ -25,5 +25,6 @@ Gem::Specification.new do |s|
25
25
  s.add_dependency "redis", "~> 3.0.4"
26
26
 
27
27
  s.add_development_dependency "rspec"
28
+ s.add_development_dependency "flexmock"
28
29
 
29
30
  end
@@ -32,6 +32,21 @@ describe Redis::Bloomfilter do
32
32
  expect { Redis::Bloomfilter.new :size => 123,:error_rate => 0.01, :driver => 'bibu' }.to raise_error(NameError)
33
33
  end
34
34
 
35
+ it 'should choose the right driver based on the Redis version' do
36
+
37
+ redis_mock = flexmock("redis")
38
+ redis_mock.should_receive(:info).and_return({'redis_version' => '2.6.0'})
39
+ redis_mock.should_receive(:script).and_return([true, true])
40
+ redis_mock_2_5 = flexmock("redis_2_5")
41
+ redis_mock_2_5.should_receive(:info).and_return({'redis_version' => '2.5.0'})
42
+
43
+ bf = factory({:size => 1000, :error_rate => 0.01, :key_name => 'ossom', :redis => redis_mock}, nil)
44
+ bf.driver.should be_kind_of(Redis::BloomfilterDriver::Lua)
45
+
46
+ bf = factory({:size => 1000, :error_rate => 0.01, :key_name => 'ossom', :redis => redis_mock_2_5}, nil)
47
+ bf.driver.should be_kind_of(Redis::BloomfilterDriver::Ruby)
48
+ end
49
+
35
50
  it 'should create a Redis::Bloomfilter object' do
36
51
  bf = factory({:size => 1000, :error_rate => 0.01, :key_name => 'ossom'}, 'ruby')
37
52
  bf.should be
@@ -72,4 +87,13 @@ describe Redis::Bloomfilter do
72
87
  end
73
88
  end
74
89
 
90
+ it 'should be a scalable bloom filter' do
91
+ bf = factory({:size => 10, :error_rate => 0.01, :key_name => '__test_bf'},'lua')
92
+ bf.clear
93
+ e = test_error_rate(bf, 1000)
94
+ e.should be < bf.options[:error_rate]
95
+ bf.clear
96
+
97
+ end
98
+
75
99
  end
data/spec/spec_helper.rb CHANGED
@@ -8,6 +8,7 @@ RSpec.configure do |config|
8
8
  config.treat_symbols_as_metadata_keys_with_true_values = true
9
9
  config.run_all_when_everything_filtered = true
10
10
  config.filter_run :focus
11
+ config.mock_with :flexmock
11
12
 
12
13
  # Run specs in random order to surface order dependencies. If you find an
13
14
  # order dependency and want to debug it, you can fix the order by providing
@@ -17,4 +18,5 @@ RSpec.configure do |config|
17
18
  end
18
19
 
19
20
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
20
- require 'redis-bloomfilter'
21
+ require "redis-bloomfilter"
22
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-bloomfilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-07 00:00:00.000000000 Z
12
+ date: 2013-07-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hiredis
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: flexmock
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  description: ! "\n Adds Redis::Bloomfilter class which can be used as ditributed
63
79
  bloom filter implementation on Redis.\n A Bloom filter is a space-efficient probabilistic
64
80
  data structure that is used to test whether an element is a member of a set.\n "