Method: CanvasSync::JobBatches::RedisScript#call

Defined in:
lib/canvas_sync/job_batches/redis_script.rb

#call(redis, *args) ⇒ Object

Passes the script and supplied arguments to redis for evaulation. It first attempts to use a script redis has already cached by using the EVALSHA command, but falls back to providing the full script text via EVAL if redis has not seen this script before. Future invocations will then use EVALSHA without erroring.

Parameters:

  • redis (Redis)

    the redis connection to run against

  • args (*Objects)

    the arguments to the script

Returns:

  • (Object)

    the value passed back by redis after script execution

Raises:

  • (LuaError)

    if the script failed to compile of encountered a runtime error



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/canvas_sync/job_batches/redis_script.rb', line 31

def call(redis, *args)
  t = Time.now
  begin
    redis.evalsha(digest, *args)
  rescue => e
    e.message =~ /NOSCRIPT/ ? redis.eval(content, *args) : raise
  end
rescue => e
  if LuaError.intercepts?(e)
    raise LuaError.new(e, @file, content)
  else
    raise
  end
end