Class: Redis::BloomfilterDriver::Ruby

Inherits:
Object
  • Object
show all
Defined in:
lib/bloomfilter_driver/ruby.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = {})
  @options = options
end

Instance Attribute Details

#redisObject

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

#clearObject

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

Returns:

  • (Boolean)


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