Class: Redis::BloomfilterDriver::RubyTest

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

Overview

It uses different hash strategy Usefule for benchmarking

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RubyTest

Returns a new instance of RubyTest.



13
14
15
# File 'lib/bloomfilter_driver/ruby_test.rb', line 13

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#redisObject

Returns the value of attribute redis.



11
12
13
# File 'lib/bloomfilter_driver/ruby_test.rb', line 11

def redis
  @redis
end

Instance Method Details

#clearObject

It deletes a bloomfilter



37
38
39
# File 'lib/bloomfilter_driver/ruby_test.rb', line 37

def clear
  @redis.del @options[:key_name]
end

#include?(key) ⇒ Boolean

It checks if a key is part of the set

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bloomfilter_driver/ruby_test.rb', line 23

def include?(key)
  indexes = []
  indexes_for(key) { |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



18
19
20
# File 'lib/bloomfilter_driver/ruby_test.rb', line 18

def insert(data)
  set data, 1
end