Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Commit

Permalink
redis instrumentation now working with redis 1.07 and redis 2.05
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl authored and bdoll committed Aug 25, 2010
1 parent 05a1e1e commit 41a5600
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ rescue LoadError
end
end

task :test => :check_dependencies
#task :test => :check_dependencies

task :default => :test

Expand Down
19 changes: 13 additions & 6 deletions lib/rpm_contrib/instrumentation/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
#

if defined?(::Redis) and not NewRelic::Control.instance['disable_redis']

::Redis.class_eval do


Redis::Client.class_eval do

include NewRelic::Agent::MethodTracer

def self.redis_call_method
Redis::Client.new.respond_to?(:call) ? :call : :raw_call_command
end


def raw_call_command_with_newrelic_trace *args
method_name = args[0].is_a?(Array) ? args[0][0] : args[0]
Expand All @@ -16,11 +22,12 @@ def raw_call_command_with_newrelic_trace *args
raw_call_command_without_newrelic_trace(*args)
end
end

# alias_method_chain :raw_call_command, :newrelic_trace
alias raw_call_command_without_newrelic_trace raw_call_command
alias raw_call_command raw_call_command_with_newrelic_trace

alias_method :raw_call_command_without_newrelic_trace, redis_call_method
alias_method redis_call_method, :raw_call_command_with_newrelic_trace

end



end
34 changes: 34 additions & 0 deletions test/test_redis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require "#{File.dirname(__FILE__)}/helper"
begin
require 'redis'
require 'ruby-debug'
rescue LoadError
end

require "#{File.dirname(__FILE__)}/../lib/rpm_contrib/instrumentation/redis"

if defined?(::Redis)


class RedisTest < Test::Unit::TestCase

# Called before every test method runs. Can be used
# to set up fixture information.
def setup
# Do nothing
end

# Called after every test method runs. Can be used to tear
# down fixture information.

def teardown
# Do nothing
end

# Fake test
def test_fail


end
end
end

0 comments on commit 41a5600

Please sign in to comment.