Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support redis-namespace client #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions activejob-traffic_control.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "minitest", "~> 5.0"
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4.7"
spec.add_development_dependency "connection_pool"
spec.add_development_dependency "redis-namespace", "~> 1.6"
end
2 changes: 1 addition & 1 deletion lib/active_job/traffic_control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def client=(cli)
def client_class_type(client)
if client.instance_of?(Dalli::Client)
Suo::Client::Memcached
elsif client.instance_of?(::Redis)
elsif client.instance_of?(::Redis) || defined?(::Redis::Namespace) && client.instance_of?(::Redis::Namespace)
Suo::Client::Redis
else
raise ArgumentError, "Unsupported client type: #{client}"
Expand Down
20 changes: 20 additions & 0 deletions test/active_job/traffic_control_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,23 @@ def setup
setup_globals
end
end

class RedisNamespacedTrafficControlTest < Minitest::Test
include ActiveJob::TrafficControlTest

def setup
ActiveJob::TrafficControl.client = Redis::Namespace.new(:namespace, redis: Redis.new)
setup_globals
end
end

class RedisNamespacedPooldedTrafficControlTest < Minitest::Test
include ActiveJob::TrafficControlTest

def setup
ActiveJob::TrafficControl.client = ConnectionPool.new(size: 5, timeout: 5) do
Redis::Namespace.new(:namespace, redis: Redis.new)
end
setup_globals
end
end
1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require "activejob/traffic_control"
require "active_job"
require "minitest/autorun"
require "redis/namespace"

test_logger = begin
l = Logger.new(STDOUT)
Expand Down