Module: Stal

Defined in:
lib/stal.rb

Constant Summary collapse

LUA =
File.expand_path("../../data/stal.lua", __FILE__)
SHA =
"4bd605bfee5f1e809089c5f98d10fab8aec38bd3"

Class Method Summary collapse

Class Method Details

.solve(c, expr) ⇒ Object

Evaluate expression ‘expr` in the Redis client `c`.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/stal.rb', line 11

def self.solve(c, expr)
  begin
    c.call!("EVALSHA", SHA, 0, JSON.dump(expr))
  rescue RuntimeError
    if $!.message["NOSCRIPT"]
      c.call!("SCRIPT", "LOAD", File.read(LUA))
      c.call!("EVALSHA", SHA, 0, JSON.dump(expr))
    else
      raise $!
    end
  end
end