Class: Conflow::Redis::Script

Inherits:
Object
  • Object
show all
Defined in:
lib/conflow/redis/script.rb

Overview

Main class for scripts, handling logic of executing and caching scripts.

Direct Known Subclasses

AddJobScript, CompleteJobScript, QueueJobsScript

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.cache_scriptsObject

This options decides whether scripts used by the gem will be cached in Redis or not. See Redis EVAL and Redis EVALSHA.

Examples:

Disable caching scripts (set this in your initializer)

Conflow::Redis::Script.cache_scripts = false


9
10
11
# File 'lib/conflow/redis/script.rb', line 9

def cache_scripts
  @cache_scripts
end

.scriptString

Returns LUA script of this Conflow::Redis::Script.

Returns:

  • (String)

    LUA script of this Conflow::Redis::Script



11
12
13
# File 'lib/conflow/redis/script.rb', line 11

def script
  @script
end

Class Method Details

.call(keys, args = []) ⇒ Object

Executes script in Redis with given arguments.

Parameters:

  • keys (Array<String>)

    Array of keys

  • args (Array<Object>) (defaults to: [])

    Array of arguments of the script



37
38
39
# File 'lib/conflow/redis/script.rb', line 37

def call(*args)
  Conflow.redis.with { |conn| send(command, conn, args) }
end

.inherited(base) ⇒ Object

Sets cache_scripts option on inherited scripts



14
15
16
17
18
# File 'lib/conflow/redis/script.rb', line 14

def inherited(base)
  scripts << base
  base.cache_scripts = cache_scripts
  super
end