Module: RedisLua
- Defined in:
- lib/redis_lua.rb,
lib/redis_lua/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Attribute Summary collapse
-
.config_file_path ⇒ Object
Returns the value of attribute config_file_path.
-
.lua_script_path ⇒ Object
Returns the value of attribute lua_script_path.
Class Method Summary collapse
- .call_script(name, *args) ⇒ Object
- .config ⇒ Object
- .load_config(file_path) ⇒ Object
- .load_script(name) ⇒ Object
- .load_scripts ⇒ Object
- .loaded_script?(name) ⇒ Boolean
- .read_script(name) ⇒ Object
Class Attribute Details
.config_file_path ⇒ Object
Returns the value of attribute config_file_path.
8 9 10 |
# File 'lib/redis_lua.rb', line 8 def config_file_path @config_file_path end |
.lua_script_path ⇒ Object
Returns the value of attribute lua_script_path.
8 9 10 |
# File 'lib/redis_lua.rb', line 8 def lua_script_path @lua_script_path end |
Class Method Details
.call_script(name, *args) ⇒ Object
43 44 45 46 |
# File 'lib/redis_lua.rb', line 43 def call_script(name, *args) sha1 = config[name] Redis.current.evalsha(sha1, *args) end |
.config ⇒ Object
10 11 12 |
# File 'lib/redis_lua.rb', line 10 def config @config ||= load_config(config_file_path) end |
.load_config(file_path) ⇒ Object
14 15 16 |
# File 'lib/redis_lua.rb', line 14 def load_config(file_path) YAML.load(File.read(file_path)) end |
.load_script(name) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/redis_lua.rb', line 29 def load_script(name) script = read_script(name) sha1 = Digest::SHA1.hexdigest(script) if sha1 == config[name] Redis.current.script(:load, script) else raise "sha1 digest mismatch: #{key} #{sha1}" end end |
.load_scripts ⇒ Object
23 24 25 26 27 |
# File 'lib/redis_lua.rb', line 23 def load_scripts config.each do |key, _| load_script(key) end end |
.loaded_script?(name) ⇒ Boolean
39 40 41 |
# File 'lib/redis_lua.rb', line 39 def loaded_script?(name) Redis.current.script(:exists, config[name]) end |
.read_script(name) ⇒ Object
18 19 20 21 |
# File 'lib/redis_lua.rb', line 18 def read_script(name) file_path = Pathname.new(lua_script_path) + "#{name}.lua" File.read(file_path) end |