Module: MeRedis::ZipValues::PrependMethods

Defined in:
lib/me_redis/zip_values.rb

Instance Method Summary collapse

Instance Method Details

#_patch_futures(client) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/me_redis/zip_values.rb', line 40

def _patch_futures(client)
  client.futures.each do |ftr|

    ftr.set_transformation do |vl|
      if vl && FutureUnzip::COMMANDS[ftr._command[0]]
        # we only dealing here with GET methods, so it could be hash getters or get/mget
        keys = ftr._command[0][0] == 'h' ? ftr._command[1,1] : ftr._command[1..-1]
        if ftr._command[0] == :mget
          vl.each_with_index.map{ |v, i| zip?(keys[i]) ? self.class.get_compressor_for_key(keys[i]).decompress( v ) : v }
        elsif zip?(keys[0])
          compressor = self.class.get_compressor_for_key(keys[0])
          # on hash commands it could be an array
          vl.is_a?(Array) ? vl.map!{|v| compressor.decompress( v ) } : compressor.decompress(vl)
        else
          vl
        end
      else
        vl
      end
    end

  end
end

#multi(&block) ⇒ Object



33
34
35
36
37
38
# File 'lib/me_redis/zip_values.rb', line 33

def multi( &block )
  super do |redis|
    block.call(redis)
    _patch_futures(@client)
  end
end

#pipelined(&block) ⇒ Object



26
27
28
29
30
31
# File 'lib/me_redis/zip_values.rb', line 26

def pipelined( &block )
  super do |redis|
    block.call(redis)
    _patch_futures(@client)
  end
end