Class: Redis::BloomfilterDriver::Lua
- Inherits:
-
Object
- Object
- Redis::BloomfilterDriver::Lua
- 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
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #clear ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize(options = {}) ⇒ Lua
constructor
A new instance of Lua.
- #insert(data) ⇒ Object
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 = @redis = @options[:redis] lua_load end |
Instance Attribute Details
#redis ⇒ Object
Returns the value of attribute redis.
12 13 14 |
# File 'lib/bloomfilter_driver/lua.rb', line 12 def redis @redis end |
Instance Method Details
#clear ⇒ Object
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
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 |