Class: Derrick::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/derrick/fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis, input, output, progress) ⇒ Fetcher

Returns a new instance of Fetcher.



5
6
7
8
9
10
# File 'lib/derrick/fetcher.rb', line 5

def initialize(redis, input, output, progress)
  @redis = redis
  @input = input
  @output = output
  @progress = progress
end

Instance Method Details

#runObject



12
13
14
15
16
17
# File 'lib/derrick/fetcher.rb', line 12

def run
  while (keys = @input.pop) != :stop
    @output.push(stats(keys))
  end
  @output.push(:stop)
end

#stats(keys) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/derrick/fetcher.rb', line 19

def stats(keys)
  types = @redis.pipelined do
    keys.each do |key|
      @redis.type(key)
    end
  end

  ttls = @redis.pipelined do
    keys.each do |key|
      @redis.ttl(key)
    end
  end

  @progress.increment_fetched(keys.size)

  keys.map.with_index do |key, index|
    Key.new(key, types[index], ttls[index])
  end
end