From 5f6a8bd7585d740389c8b95f3031a9da284f8f68 Mon Sep 17 00:00:00 2001 From: eileencodes Date: Fri, 8 Dec 2017 15:09:23 -0500 Subject: [PATCH] Backport #30748 for redis-rb 4.0 support Rails master adds support for redis-rb 4.0 but when Rails 5-1-stable branch gets an updated redis there are exceptions in the travis log. ``` Error: RedisAdapterTest#test_channel_filtered_broadcast: Gem::LoadError: Specified 'redis' for Action Cable pubsub adapter, but the gem is not loaded. Add `gem 'redis'` to your Gemfile (and ensure its version is at the minimum required by Action Cable). ``` This PR backports Jeremy's work so that the build can be green. [Eileen M. Uchitelle & Jeremy Daer] --- .../subscription_adapter/evented_redis.rb | 8 ++++---- .../lib/action_cable/subscription_adapter/redis.rb | 6 +++--- activejob/CHANGELOG.md | 7 ++++++- activejob/test/support/integration/adapters/resque.rb | 11 ++++------- railties/CHANGELOG.md | 7 ++++++- railties/lib/rails/generators/app_base.rb | 2 +- 6 files changed, 24 insertions(+), 17 deletions(-) diff --git a/actioncable/lib/action_cable/subscription_adapter/evented_redis.rb b/actioncable/lib/action_cable/subscription_adapter/evented_redis.rb index d3a00f4f2f9d..b4b499d88673 100644 --- a/actioncable/lib/action_cable/subscription_adapter/evented_redis.rb +++ b/actioncable/lib/action_cable/subscription_adapter/evented_redis.rb @@ -1,9 +1,9 @@ require 'thread' -gem 'em-hiredis', '~> 0.3.0' -gem 'redis', '~> 3.0' -require 'em-hiredis' -require 'redis' +gem "em-hiredis", "~> 0.3.0" +gem "redis", ">= 3", "< 5" +require "em-hiredis" +require "redis" EventMachine.epoll if EventMachine.epoll? EventMachine.kqueue if EventMachine.kqueue? diff --git a/actioncable/lib/action_cable/subscription_adapter/redis.rb b/actioncable/lib/action_cable/subscription_adapter/redis.rb index 65434f71070a..b9dc53f3f6dd 100644 --- a/actioncable/lib/action_cable/subscription_adapter/redis.rb +++ b/actioncable/lib/action_cable/subscription_adapter/redis.rb @@ -1,7 +1,7 @@ require 'thread' -gem 'redis', '~> 3.0' -require 'redis' +gem "redis", ">= 3", "< 5" +require "redis" module ActionCable module SubscriptionAdapter @@ -70,7 +70,7 @@ def initialize(adapter, event_loop) def listen(conn) conn.without_reconnect do - original_client = conn.client + original_client = conn.respond_to?(:_client) ? conn._client : conn.client conn.subscribe('_action_cable_internal') do |on| on.subscribe do |chan, count| diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index 912f2143a2a9..8471c0fdde77 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -1,4 +1,9 @@ -## Rails 5.0.7.2 (March 11, 2019) ## +## Rails 5.0.7.2.brilliant (March 11, 2019) ## +* Gemfile for new apps: upgrade redis-rb from ~> 3.0 to 4.0. + + *Jeremy Daer* + +## Rails 5.1.4 (September 07, 2017) ## * No changes. diff --git a/activejob/test/support/integration/adapters/resque.rb b/activejob/test/support/integration/adapters/resque.rb index 912f4bc387fc..dad292ae580d 100644 --- a/activejob/test/support/integration/adapters/resque.rb +++ b/activejob/test/support/integration/adapters/resque.rb @@ -1,7 +1,7 @@ module ResqueJobsManager def setup ActiveJob::Base.queue_adapter = :resque - Resque.redis = Redis::Namespace.new 'active_jobs_int_test', redis: Redis.connect(url: "redis://127.0.0.1:6379/12", :thread_safe => true) + Resque.redis = Redis::Namespace.new "active_jobs_int_test", redis: Redis.new(url: "redis://127.0.0.1:6379/12", thread_safe: true) Resque.logger = Rails.logger unless can_run? puts "Cannot run integration tests for resque. To be able to run integration tests for resque you need to install and start redis.\n" @@ -39,11 +39,8 @@ def stop_workers end def can_run? - begin - Resque.redis.client.connect - rescue - return false - end - true + Resque.redis.ping == "PONG" + rescue + false end end diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index fc58f16e30b7..0aa14ab54224 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,4 +1,9 @@ -## Rails 5.0.7.2 (March 11, 2019) ## +## Rails 5.0.7.2.brilliant (March 11, 2019) ## +* Gemfile for new apps: upgrade redis-rb from ~> 3.0 to 4.0. + + *Jeremy Daer* + +## Rails 5.1.4 (September 07, 2017) ## * No changes. diff --git a/railties/lib/rails/generators/app_base.rb b/railties/lib/rails/generators/app_base.rb index 788553edb335..8ca085bf0dd1 100644 --- a/railties/lib/rails/generators/app_base.rb +++ b/railties/lib/rails/generators/app_base.rb @@ -353,7 +353,7 @@ def cable_gemfile_entry return [] if options[:skip_action_cable] comment = 'Use Redis adapter to run Action Cable in production' gems = [] - gems << GemfileEntry.new("redis", '~> 3.0', comment, {}, true) + gems << GemfileEntry.new("redis", "~> 4.0", comment, {}, true) gems end