Class: TimeBandits::TimeConsumers::Redis::Subscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/time_bandits/time_consumers/redis.rb

Instance Method Summary collapse

Instance Method Details

#request(event) ⇒ Object



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
41
42
43
44
45
46
47
48
49
# File 'lib/time_bandits/time_consumers/redis.rb', line 16

def request(event)
  i = Redis.instance
  i.time += event.duration
  i.calls += 1 # count redis round trips, not calls

  return unless logger.debug?

  name = "%s (%.2fms)" % ["Redis", event.duration]
  cmds = event.payload[:commands]

  # output = "  #{color(name, CYAN, true)}"
  output = "  #{name}"

  cmds.each do |cmd, *args|
    if args.present?
      logged_args = args.map do |a|
        case
        when a.respond_to?(:inspect) then a.inspect
        when a.respond_to?(:to_s)    then a.to_s
        else
          # handle poorly-behaved descendants of BasicObject
          klass = a.instance_exec { (class << self; self end).superclass }
          "\#<#{klass}:#{a.__id__}>"
        end
      end

      output << " [ #{cmd.to_s.upcase} #{logged_args.join(" ")} ]"
    else
      output << " [ #{cmd.to_s.upcase} ]"
    end
  end

  debug output
end