diff options
author | Jon Moss <me@jonathanmoss.me> | 2016-01-16 10:33:50 -0500 |
---|---|---|
committer | Jon Moss <me@jonathanmoss.me> | 2016-01-18 19:37:25 -0500 |
commit | ae31da20cd250154c951b67d5625fc71ac27e2f1 (patch) | |
tree | 8f9bf6275f9e52c3b8a8b674d0bfd2a941f5bdf9 /actioncable/lib/action_cable/subscription_adapter | |
parent | 980e01eb100b38e39791f7f930a038ecaf7c02da (diff) | |
download | rails-ae31da20cd250154c951b67d5625fc71ac27e2f1.tar.gz rails-ae31da20cd250154c951b67d5625fc71ac27e2f1.tar.bz2 rails-ae31da20cd250154c951b67d5625fc71ac27e2f1.zip |
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
Diffstat (limited to 'actioncable/lib/action_cable/subscription_adapter')
-rw-r--r-- | actioncable/lib/action_cable/subscription_adapter/postgresql.rb | 8 | ||||
-rw-r--r-- | actioncable/lib/action_cable/subscription_adapter/redis.rb | 41 |
2 files changed, 19 insertions, 30 deletions
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 |