Class: Execache::Client
- Inherits:
-
Object
- Object
- Execache::Client
- Defined in:
- lib/execache/client.rb
Instance Attribute Summary collapse
-
#redis_1 ⇒ Object
readonly
Returns the value of attribute redis_1.
-
#redis_2 ⇒ Object
readonly
Returns the value of attribute redis_2.
Instance Method Summary collapse
- #exec(options) ⇒ Object
-
#initialize(redis_url) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(redis_url) ⇒ Client
Returns a new instance of Client.
6 7 8 9 |
# File 'lib/execache/client.rb', line 6 def initialize(redis_url) @redis_1 = Redis.connect(:url => "redis://#{redis_url}") @redis_2 = Redis.connect(:url => "redis://#{redis_url}") end |
Instance Attribute Details
#redis_1 ⇒ Object (readonly)
Returns the value of attribute redis_1.
4 5 6 |
# File 'lib/execache/client.rb', line 4 def redis_1 @redis_1 end |
#redis_2 ⇒ Object (readonly)
Returns the value of attribute redis_2.
4 5 6 |
# File 'lib/execache/client.rb', line 4 def redis_2 @redis_2 end |
Instance Method Details
#exec(options) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/execache/client.rb', line 11 def exec() wait = .delete(:wait) subscribe_to = [:channel] = Digest::SHA1.hexdigest("#{rand}") = Yajl::Encoder.encode() response = nil Timeout.timeout(60) do @redis_1.subscribe("execache:response:#{subscribe_to}") do |on| on.subscribe do |channel, subscriptions| @redis_2.rpush "execache:request", end on. do |channel, | if .include?('[PENDING]') if wait == false response = false @redis_1.unsubscribe else @redis_2.rpush "execache:request", end else response = Yajl::Parser.parse() @redis_1.unsubscribe end end end end response end |