Class: MultiRedis::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_redis/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(redis, shared_context = nil) ⇒ Context

Returns a new instance of Context.


7
8
9
10
11
12
# File 'lib/multi_redis/context.rb', line 7

def initialize redis, shared_context = nil
  @redis = redis
  @data = Data.new
  @last_replies = []
  @shared_context = shared_context
end

Instance Attribute Details

#last_repliesObject

Returns the value of attribute last_replies


5
6
7
# File 'lib/multi_redis/context.rb', line 5

def last_replies
  @last_replies
end

#last_resultObject

Returns the value of attribute last_result


4
5
6
# File 'lib/multi_redis/context.rb', line 4

def last_result
  @last_result
end

Instance Method Details

#dataObject


32
33
34
# File 'lib/multi_redis/context.rb', line 32

def data
  @data
end

#execute(operation, *args) ⇒ Object


14
15
16
17
18
19
20
21
22
# File 'lib/multi_redis/context.rb', line 14

def execute operation, *args
  @last_result = operation.execute self, *args
  if @resolve = @redis.client.respond_to?(:futures)
    @last_replies = @redis.client.futures[@shared_context.last_replies.length, @redis.client.futures.length]
    @shared_context.last_replies.concat @last_replies
  end
  @shared_context.last_result = @last_result
  @last_result
end

#redisObject


28
29
30
# File 'lib/multi_redis/context.rb', line 28

def redis
  @redis
end

#resolve_futures!Object


36
37
38
39
40
41
42
# File 'lib/multi_redis/context.rb', line 36

def resolve_futures!
  return unless @resolve
  @data.each_key do |k|
    @data[k] = @data[k].value if @data[k].is_a? Redis::Future
  end
  @last_replies.collect!{ |r| r.is_a?(Redis::Future) ? r.value : r }
end

#sharedObject


24
25
26
# File 'lib/multi_redis/context.rb', line 24

def shared
  @shared_context
end