From ae31da20cd250154c951b67d5625fc71ac27e2f1 Mon Sep 17 00:00:00 2001 From: Jon Moss Date: Sat, 16 Jan 2016 10:33:50 -0500 Subject: Fix code review comments - adapter -> pubsub (re)rename internally - Change variable names to match method names - Add EventMachine `~> 1.0` as a runtime dependency of ActionCable - Refactor dependency loading for adapters --- .../subscription_adapter/postgresql.rb | 8 ++--- .../lib/action_cable/subscription_adapter/redis.rb | 41 +++++++++------------- 2 files changed, 19 insertions(+), 30 deletions(-) (limited to 'actioncable/lib/action_cable/subscription_adapter') diff --git a/actioncable/lib/action_cable/subscription_adapter/postgresql.rb b/actioncable/lib/action_cable/subscription_adapter/postgresql.rb index afa99355e8..64c519beed 100644 --- a/actioncable/lib/action_cable/subscription_adapter/postgresql.rb +++ b/actioncable/lib/action_cable/subscription_adapter/postgresql.rb @@ -1,11 +1,7 @@ +gem 'pg', '~> 0.18' +require 'pg' require 'thread' -begin - require 'pg' -rescue Gem::LoadError => e - raise Gem::LoadError, "You are trying to use the PostgreSQL ActionCable adapter, but do not have the proper gems installed. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActionCable)." -end - module ActionCable module SubscriptionAdapter class PostgreSQL < Base # :nodoc: diff --git a/actioncable/lib/action_cable/subscription_adapter/redis.rb b/actioncable/lib/action_cable/subscription_adapter/redis.rb index c6d8371f16..9615430be4 100644 --- a/actioncable/lib/action_cable/subscription_adapter/redis.rb +++ b/actioncable/lib/action_cable/subscription_adapter/redis.rb @@ -1,19 +1,18 @@ -begin - require 'em-hiredis' - require 'redis' -rescue Gem::LoadError => e - raise Gem::LoadError, "You are trying to use the Redis ActionCable adapter, but do not have the proper gems installed. Add `gem 'em-hiredis'` and `gem 'redis'` to your Gemfile (and ensure its version is at the minimum required by ActionCable)." -end +gem 'em-hiredis', '~> 0.3.0' +gem 'redis', '~> 3.0' +require 'em-hiredis' +require 'redis' module ActionCable module SubscriptionAdapter - class Redis < Base + class Redis < Base # :nodoc: + # The redis instance used for broadcasting. Not intended for direct user use. def broadcast(channel, payload) - redis_conn.publish(channel, payload) + broadcast_redis_connection.publish(channel, payload) end def subscribe(channel, message_callback, success_callback = nil) - hi_redis_conn.pubsub.subscribe(channel, &message_callback).tap do |result| + subscription_redis_connection.pubsub.subscribe(channel, &message_callback).tap do |result| result.callback(&success_callback) if success_callback end end @@ -23,23 +22,17 @@ module ActionCable end private - - # The redis instance used for broadcasting. Not intended for direct user use. - def redis_conn - @broadcast ||= ::Redis.new(@server.config.config_opts) - end - - # The EventMachine Redis instance used by the pubsub adapter. - def hi_redis_conn - @hi_redis_conn ||= EM::Hiredis.connect(@server.config.cable[:url]).tap do |redis| - redis.on(:reconnect_failed) do - @logger.info "[ActionCable] Redis reconnect failed." + def subscription_redis_connection + @subscription_redis_connection ||= EM::Hiredis.connect(@server.config.cable[:url]).tap do |redis| + redis.on(:reconnect_failed) do + @logger.info "[ActionCable] Redis reconnect failed." + end end end - end - def redis_conn - @redis_conn ||= ::Redis.new(@server.config.cable) - end + + def broadcast_redis_connection + @broadcast_redis_connection ||= ::Redis.new(@server.config.cable) + end end end end -- cgit v1.2.3