Class: Redis::BloomfilterDriver::Ruby
- Inherits:
-
Object
- Object
- Redis::BloomfilterDriver::Ruby
- Defined in:
- lib/bloomfilter_driver/ruby.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
Faster Ruby version.
Instance Method Summary collapse
-
#clear ⇒ Object
It deletes a bloomfilter.
-
#include?(key) ⇒ Boolean
It checks if a key is part of the set.
-
#initialize(options = {}) ⇒ Ruby
constructor
A new instance of Ruby.
-
#insert(data) ⇒ Object
Insert a new element.
Constructor Details
#initialize(options = {}) ⇒ Ruby
Returns a new instance of Ruby.
10 11 12 |
# File 'lib/bloomfilter_driver/ruby.rb', line 10 def initialize( = {}) @options = end |
Instance Attribute Details
#redis ⇒ Object
Faster Ruby version. This driver should be used if Redis version < 2.6
9 10 11 |
# File 'lib/bloomfilter_driver/ruby.rb', line 9 def redis @redis end |
Instance Method Details
#clear ⇒ Object
It deletes a bloomfilter
33 34 35 |
# File 'lib/bloomfilter_driver/ruby.rb', line 33 def clear @redis.del @options[:key_name] end |
#include?(key) ⇒ Boolean
It checks if a key is part of the set
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/bloomfilter_driver/ruby.rb', line 20 def include?(key) indexes = [] indexes_for(key).each { |idx| indexes << idx } return false if @redis.getbit(@options[:key_name], indexes.shift).zero? result = @redis.pipelined do indexes.each { |idx| @redis.getbit(@options[:key_name], idx) } end !result.include?(0) end |
#insert(data) ⇒ Object
Insert a new element
15 16 17 |
# File 'lib/bloomfilter_driver/ruby.rb', line 15 def insert(data) set data, 1 end |