Removed deprected evented redis adapter
This commit is contained in:
parent
e16c765ac6
commit
48766e32d3
|
@ -1,3 +1,7 @@
|
|||
* Removed deprecated evented redis adapter.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Support redis-rb 4.0.
|
||||
|
||||
*Jeremy Daer*
|
||||
|
|
|
@ -446,7 +446,7 @@ The WebSocket server doesn't have access to the session, but it has access to th
|
|||
|
||||
## Dependencies
|
||||
|
||||
Action Cable provides a subscription adapter interface to process its pubsub internals. By default, asynchronous, inline, PostgreSQL, evented Redis, and non-evented Redis adapters are included. The default adapter in new Rails applications is the asynchronous (`async`) adapter. To create your own adapter, you can look at `ActionCable::SubscriptionAdapter::Base` for all methods that must be implemented, and any of the adapters included within Action Cable as example implementations.
|
||||
Action Cable provides a subscription adapter interface to process its pubsub internals. By default, asynchronous, inline, PostgreSQL, and Redis adapters are included. The default adapter in new Rails applications is the asynchronous (`async`) adapter. To create your own adapter, you can look at `ActionCable::SubscriptionAdapter::Base` for all methods that must be implemented, and any of the adapters included within Action Cable as example implementations.
|
||||
|
||||
The Ruby side of things is built on top of [websocket-driver](https://github.com/faye/websocket-driver-ruby), [nio4r](https://github.com/celluloid/nio4r), and [concurrent-ruby](https://github.com/ruby-concurrency/concurrent-ruby).
|
||||
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "thread"
|
||||
|
||||
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?
|
||||
|
||||
module ActionCable
|
||||
module SubscriptionAdapter
|
||||
class EventedRedis < Base # :nodoc:
|
||||
prepend ChannelPrefix
|
||||
|
||||
@@mutex = Mutex.new
|
||||
|
||||
# Overwrite this factory method for EventMachine Redis connections if you want to use a different Redis connection library than EM::Hiredis.
|
||||
# This is needed, for example, when using Makara proxies for distributed Redis.
|
||||
cattr_accessor :em_redis_connector, default: ->(config) { EM::Hiredis.connect(config[:url]) }
|
||||
|
||||
# Overwrite this factory method for Redis connections if you want to use a different Redis connection library than Redis.
|
||||
# This is needed, for example, when using Makara proxies for distributed Redis.
|
||||
cattr_accessor :redis_connector, default: ->(config) { ::Redis.new(url: config[:url]) }
|
||||
|
||||
def initialize(*)
|
||||
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||
The "evented_redis" subscription adapter is deprecated and
|
||||
will be removed in Rails 5.2. Please use the "redis" adapter
|
||||
instead.
|
||||
MSG
|
||||
|
||||
super
|
||||
@redis_connection_for_broadcasts = @redis_connection_for_subscriptions = nil
|
||||
end
|
||||
|
||||
def broadcast(channel, payload)
|
||||
redis_connection_for_broadcasts.publish(channel, payload)
|
||||
end
|
||||
|
||||
def subscribe(channel, message_callback, success_callback = nil)
|
||||
redis_connection_for_subscriptions.pubsub.subscribe(channel, &message_callback).tap do |result|
|
||||
result.callback { |reply| success_callback.call } if success_callback
|
||||
end
|
||||
end
|
||||
|
||||
def unsubscribe(channel, message_callback)
|
||||
redis_connection_for_subscriptions.pubsub.unsubscribe_proc(channel, message_callback)
|
||||
end
|
||||
|
||||
def shutdown
|
||||
redis_connection_for_subscriptions.pubsub.close_connection
|
||||
@redis_connection_for_subscriptions = nil
|
||||
end
|
||||
|
||||
private
|
||||
def redis_connection_for_subscriptions
|
||||
ensure_reactor_running
|
||||
@redis_connection_for_subscriptions || @server.mutex.synchronize do
|
||||
@redis_connection_for_subscriptions ||= self.class.em_redis_connector.call(@server.config.cable).tap do |redis|
|
||||
redis.on(:reconnect_failed) do
|
||||
@logger.error "[ActionCable] Redis reconnect failed."
|
||||
end
|
||||
|
||||
redis.on(:failed) do
|
||||
@logger.error "[ActionCable] Redis connection has failed."
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def redis_connection_for_broadcasts
|
||||
@redis_connection_for_broadcasts || @server.mutex.synchronize do
|
||||
@redis_connection_for_broadcasts ||= self.class.redis_connector.call(@server.config.cable)
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_reactor_running
|
||||
return if EventMachine.reactor_running? && EventMachine.reactor_thread
|
||||
@@mutex.synchronize do
|
||||
Thread.new { EventMachine.run } unless EventMachine.reactor_running?
|
||||
Thread.pass until EventMachine.reactor_running? && EventMachine.reactor_thread
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,61 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
require_relative "common"
|
||||
require_relative "channel_prefix"
|
||||
|
||||
class EventedRedisAdapterTest < ActionCable::TestCase
|
||||
include CommonSubscriptionAdapterTest
|
||||
include ChannelPrefixTest
|
||||
|
||||
def setup
|
||||
assert_deprecated do
|
||||
super
|
||||
end
|
||||
|
||||
# em-hiredis is warning-rich
|
||||
@previous_verbose, $VERBOSE = $VERBOSE, nil
|
||||
end
|
||||
|
||||
def teardown
|
||||
super
|
||||
|
||||
# Ensure EM is shut down before we re-enable warnings
|
||||
EventMachine.reactor_thread.tap do |thread|
|
||||
EventMachine.stop
|
||||
thread.join
|
||||
end
|
||||
|
||||
$VERBOSE = @previous_verbose
|
||||
end
|
||||
|
||||
def test_slow_eventmachine
|
||||
require "eventmachine"
|
||||
require "thread"
|
||||
|
||||
lock = Mutex.new
|
||||
|
||||
EventMachine.singleton_class.class_eval do
|
||||
alias_method :delayed_initialize_event_machine, :initialize_event_machine
|
||||
define_method(:initialize_event_machine) do
|
||||
lock.synchronize do
|
||||
sleep 0.5
|
||||
delayed_initialize_event_machine
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test_basic_broadcast
|
||||
ensure
|
||||
lock.synchronize do
|
||||
EventMachine.singleton_class.class_eval do
|
||||
alias_method :initialize_event_machine, :delayed_initialize_event_machine
|
||||
remove_method :delayed_initialize_event_machine
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def cable_config
|
||||
{ adapter: "evented_redis", url: "redis://:password@127.0.0.1:6379/12" }
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue