Class: XRuntime::Script
- Inherits:
-
Object
- Object
- XRuntime::Script
- Defined in:
- lib/x_runtime/script.rb
Instance Attribute Summary collapse
-
#redis ⇒ Object
Returns the value of attribute redis.
Instance Method Summary collapse
- #evalsha(operate, keys, argv) ⇒ Object
-
#initialize(redis) ⇒ Script
constructor
A new instance of Script.
- #load ⇒ Object
- #sha ⇒ Object
Constructor Details
#initialize(redis) ⇒ Script
Returns a new instance of Script.
5 6 7 8 9 10 11 12 |
# File 'lib/x_runtime/script.rb', line 5 def initialize(redis) @redis = redis @scripts = {} @sha = {} load sha end |
Instance Attribute Details
#redis ⇒ Object
Returns the value of attribute redis.
3 4 5 |
# File 'lib/x_runtime/script.rb', line 3 def redis @redis end |
Instance Method Details
#evalsha(operate, keys, argv) ⇒ Object
31 32 33 |
# File 'lib/x_runtime/script.rb', line 31 def evalsha(operate, keys, argv) @redis.evalsha(@sha[operate], :keys => keys, :argv => argv) end |
#load ⇒ Object
14 15 16 17 18 19 |
# File 'lib/x_runtime/script.rb', line 14 def load Dir[::File.join(::File.dirname(__FILE__), 'lua', '*.lua')].each do |lua| act = /(\w*)\.lua/.match(File.basename(lua))[1] @scripts[act.to_sym] = IO.read(lua) if act end end |
#sha ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/x_runtime/script.rb', line 21 def sha # 加载脚本 redis-server会将该脚本缓存起来 if @sha.empty? @scripts.each do |key, content| @sha[key] ||= @redis.script(:load, content) end end end |