Class: Redis::BloomfilterDriver::Lua

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

Overview

It loads lua script into redis. BF implementation is done by lua scripting The alghoritm is executed directly on redis Credits for lua code goes to Erik Dubbelboer github.com/ErikDubbelboer/redis-lua-scaling-bloom-filter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Lua

Returns a new instance of Lua.



14
15
16
17
18
# File 'lib/bloomfilter_driver/lua.rb', line 14

def initialize(options = {})
  @options = options
  @redis = @options[:redis]
  lua_load
end

Instance Attribute Details

#redisObject

Returns the value of attribute redis.



12
13
14
# File 'lib/bloomfilter_driver/lua.rb', line 12

def redis
  @redis
end

Instance Method Details

#clearObject



29
30
31
# File 'lib/bloomfilter_driver/lua.rb', line 29

def clear
  @redis.keys("#{@options[:key_name]}:*").each { |k| @redis.del k }
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/bloomfilter_driver/lua.rb', line 24

def include?(key)
  r = @redis.evalsha(@check_fnc_sha, keys: [@options[:key_name]], argv: [@options[:size], @options[:error_rate], key])
  r == 1
end

#insert(data) ⇒ Object



20
21
22
# File 'lib/bloomfilter_driver/lua.rb', line 20

def insert(data)
  set data, 1
end