Class: Fairway::Scripts

Inherits:
Object
  • Object
show all
Defined in:
lib/fairway/scripts.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis, namespace) ⇒ Scripts

Returns a new instance of Scripts.



10
11
12
13
# File 'lib/fairway/scripts.rb', line 10

def initialize(redis, namespace)
  @redis = redis
  @namespace = namespace
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fairway/scripts.rb', line 23

def method_missing(method_name, *args)
  loaded = false
  @redis.evalsha(script_sha(method_name), [namespace], args)
rescue Redis::CommandError => ex
  if ex.message.include?("NOSCRIPT") && !loaded
    @redis.script(:load, script_source(method_name))
    loaded = true
    retry
  else
    raise
  end
end

Class Method Details

.script_shasObject



6
7
8
# File 'lib/fairway/scripts.rb', line 6

def self.script_shas
  @script_shas ||= {}
end

Instance Method Details

#register_queue(name, channel) ⇒ Object



15
16
17
# File 'lib/fairway/scripts.rb', line 15

def register_queue(name, channel)
  @redis.hset(registered_queues_key, name, channel)
end

#registered_queuesObject



19
20
21
# File 'lib/fairway/scripts.rb', line 19

def registered_queues
  @redis.hgetall(registered_queues_key)
end