Sha256: 004350747627c637ea423b14f67d4c1a3a0d6615aa48fdf47dbd2e706db25d7f

Contents?: true

Size: 813 Bytes

Versions: 3

Compression:

Stored size: 813 Bytes

Contents

module Cacheflow
  module Redis
    module Notifications
      def logging(commands)
        payload = {
          commands: commands
        }
        ActiveSupport::Notifications.instrument("query.redis", payload) do
          super
        end
      end
    end

    class Instrumenter < ActiveSupport::LogSubscriber
      def query(event)
        return if !logger.debug? || Cacheflow.silenced?

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

        commands = []
        event.payload[:commands].map do |op, *args|
          commands << "#{op.to_s.upcase} #{args.join(" ")}".strip
        end

        debug "  #{color(name, RED, true)} #{commands.join(" >> ")}"
      end
    end
  end
end

Redis::Client.prepend(Cacheflow::Redis::Notifications)
Cacheflow::Redis::Instrumenter.attach_to(:redis)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cacheflow-0.2.1 lib/cacheflow/redis.rb
cacheflow-0.2.0 lib/cacheflow/redis.rb
cacheflow-0.1.1 lib/cacheflow/redis.rb