Skip to content

Commit

Permalink
Add redis-client support
Browse files Browse the repository at this point in the history
With version 5 of the redis gem the client was moved into a separate
gem. Since then the redis integration stopped working.
  • Loading branch information
jbockler committed Jan 17, 2024
1 parent 7868633 commit d44f709
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 77 deletions.
6 changes: 6 additions & 0 deletions .changesets/add-redis-client-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
bump: "patch"
type: "add"
---

Add support for the `redis-client` gem, which is used by the redis gem since version 5.
144 changes: 144 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,42 @@ blocks:
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 2.7.8 for redis-4
env_vars:
- *2
- *3
- *4
- *5
- name: RUBY_VERSION
value: 2.7.8
- name: GEMSET
value: redis-4
- name: BUNDLE_GEMFILE
value: gemfiles/redis-4.gemfile
- name: _RUBYGEMS_VERSION
value: latest
- name: _BUNDLER_VERSION
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 2.7.8 for redis-5
env_vars:
- *2
- *3
- *4
- *5
- name: RUBY_VERSION
value: 2.7.8
- name: GEMSET
value: redis-5
- name: BUNDLE_GEMFILE
value: gemfiles/redis-5.gemfile
- name: _RUBYGEMS_VERSION
value: latest
- name: _BUNDLER_VERSION
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.0.5
dependencies:
- Validation
Expand Down Expand Up @@ -899,6 +935,42 @@ blocks:
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.0.5 for redis-4
env_vars:
- *2
- *3
- *4
- *5
- name: RUBY_VERSION
value: 3.0.5
- name: GEMSET
value: redis-4
- name: BUNDLE_GEMFILE
value: gemfiles/redis-4.gemfile
- name: _RUBYGEMS_VERSION
value: latest
- name: _BUNDLER_VERSION
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.0.5 for redis-5
env_vars:
- *2
- *3
- *4
- *5
- name: RUBY_VERSION
value: 3.0.5
- name: GEMSET
value: redis-5
- name: BUNDLE_GEMFILE
value: gemfiles/redis-5.gemfile
- name: _RUBYGEMS_VERSION
value: latest
- name: _BUNDLER_VERSION
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.1.3
dependencies:
- Validation
Expand Down Expand Up @@ -1280,6 +1352,42 @@ blocks:
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.1.3 for redis-4
env_vars:
- *2
- *3
- *4
- *5
- name: RUBY_VERSION
value: 3.1.3
- name: GEMSET
value: redis-4
- name: BUNDLE_GEMFILE
value: gemfiles/redis-4.gemfile
- name: _RUBYGEMS_VERSION
value: latest
- name: _BUNDLER_VERSION
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.1.3 for redis-5
env_vars:
- *2
- *3
- *4
- *5
- name: RUBY_VERSION
value: 3.1.3
- name: GEMSET
value: redis-5
- name: BUNDLE_GEMFILE
value: gemfiles/redis-5.gemfile
- name: _RUBYGEMS_VERSION
value: latest
- name: _BUNDLER_VERSION
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.2.1
dependencies:
- Validation
Expand Down Expand Up @@ -1661,6 +1769,42 @@ blocks:
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.2.1 for redis-4
env_vars:
- *2
- *3
- *4
- *5
- name: RUBY_VERSION
value: 3.2.1
- name: GEMSET
value: redis-4
- name: BUNDLE_GEMFILE
value: gemfiles/redis-4.gemfile
- name: _RUBYGEMS_VERSION
value: latest
- name: _BUNDLER_VERSION
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby 3.2.1 for redis-5
env_vars:
- *2
- *3
- *4
- *5
- name: RUBY_VERSION
value: 3.2.1
- name: GEMSET
value: redis-5
- name: BUNDLE_GEMFILE
value: gemfiles/redis-5.gemfile
- name: _RUBYGEMS_VERSION
value: latest
- name: _BUNDLER_VERSION
value: latest
commands:
- "./support/bundler_wrapper exec rake test"
- name: Ruby jruby-9.4.1.0
dependencies:
- Validation
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ BUNDLE_GEMFILE=gemfiles/sequel-435.gemfile bundle exec rspec
BUNDLE_GEMFILE=gemfiles/sequel.gemfile bundle exec rspec
BUNDLE_GEMFILE=gemfiles/sinatra.gemfile bundle exec rspec
BUNDLE_GEMFILE=gemfiles/webmachine.gemfile bundle exec rspec
BUNDLE_GEMFILE=gemfiles/redis-4.gemfile bundle exec rspec
BUNDLE_GEMFILE=gemfiles/redis-5.gemfile bundle exec rspec
```

If you have either [RVM][rvm], [rbenv][rbenv] or [chruby][chruby] installed you
Expand Down
2 changes: 2 additions & 0 deletions build_matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,5 @@ matrix:
- gem: "sinatra"
- gem: "webmachine1"
- gem: "webmachine2"
- gem: "redis-4"
- gem: "redis-5"
5 changes: 5 additions & 0 deletions gemfiles/redis-4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source 'https://rubygems.org'

gem 'redis', "~> 4.0"

gemspec :path => '../'
6 changes: 6 additions & 0 deletions gemfiles/redis-5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source 'https://rubygems.org'

gem 'redis', '~> 5.0'
gem 'hiredis-client'

gemspec :path => '../'
1 change: 1 addition & 0 deletions lib/appsignal/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def self.const_missing(name)
require "appsignal/hooks/puma"
require "appsignal/hooks/rake"
require "appsignal/hooks/redis"
require "appsignal/hooks/redis_client"
require "appsignal/hooks/resque"
require "appsignal/hooks/sequel"
require "appsignal/hooks/shoryuken"
Expand Down
1 change: 1 addition & 0 deletions lib/appsignal/hooks/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class RedisHook < Appsignal::Hooks::Hook

def dependencies_present?
defined?(::Redis) &&
!defined?(::RedisClient) &&
Appsignal.config &&
Appsignal.config[:instrument_redis]
end
Expand Down
27 changes: 27 additions & 0 deletions lib/appsignal/hooks/redis_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# frozen_string_literal: true

module Appsignal
class Hooks
# @api private
class RedisClientHook < Appsignal::Hooks::Hook
register :redis_client

def dependencies_present?
defined?(::RedisClient) &&
Appsignal.config &&
Appsignal.config[:instrument_redis]
end

def install
require "appsignal/integrations/redis_client"
::RedisClient::RubyConnection.prepend Appsignal::Integrations::RedisClientIntegration
Appsignal::Environment.report_enabled("redis")

return unless defined?(::RedisClient::HiredisConnection)

::RedisClient::HiredisConnection.prepend Appsignal::Integrations::RedisClientIntegration
Appsignal::Environment.report_enabled("hiredis")
end
end
end
end
20 changes: 20 additions & 0 deletions lib/appsignal/integrations/redis_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Appsignal
module Integrations
module RedisClientIntegration
def write(command)
sanitized_command =
if command[0] == :eval
"#{command[1]}#{" ?" * (command.size - 3)}"
else
"#{command[0]}#{" ?" * (command.size - 1)}"
end

Appsignal.instrument "query.redis", @config.id, sanitized_command do
super
end
end
end
end
end
Loading

0 comments on commit d44f709

Please sign in to comment.