Skip to content

Commit

Permalink
Backport rails#30748 for redis-rb 4.0 support
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
eileencodes authored and toby-brilliant committed Apr 29, 2022
1 parent c4d3e20 commit 5f6a8bd
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
@@ -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?
Expand Down
6 changes: 3 additions & 3 deletions 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
Expand Down Expand Up @@ -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|
Expand Down
7 changes: 6 additions & 1 deletion 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.

Expand Down
11 changes: 4 additions & 7 deletions 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"
Expand Down Expand Up @@ -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
7 changes: 6 additions & 1 deletion 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.

Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/generators/app_base.rb
Expand Up @@ -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

Expand Down

0 comments on commit 5f6a8bd

Please sign in to comment.