From c40e52ea68e21ba5b098343c7e1f285800f97008 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 7 Feb 2015 00:47:45 +0530 Subject: Use just one redis connection --- lib/action_cable/channel/redis.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/action_cable/channel/redis.rb b/lib/action_cable/channel/redis.rb index 215cc3c975..2aca785cbe 100644 --- a/lib/action_cable/channel/redis.rb +++ b/lib/action_cable/channel/redis.rb @@ -10,21 +10,22 @@ module ActionCable def subscribe_to(redis_channel, callback = nil) @_redis_channels ||= [] - @_redis_channels << redis_channel callback ||= -> (message) { broadcast ActiveSupport::JSON.decode(message) } - redis.pubsub.subscribe(redis_channel, &callback) + @_redis_channels << [ redis_channel, callback ] + + pubsub.subscribe(redis_channel, &callback) end protected def unsubscribe_from_redis_channels if @_redis_channels - @_redis_channels.each { |channel| @connection.pubsub.unsubscribe(channel) } + @_redis_channels.each { |channel, callback| pubsub.unsubscribe_proc(channel, callback) } end end - def redis - @connection.redis + def pubsub + @connection.pubsub end end -- cgit v1.2.3 From 05309cdf3858d4e65bda3fb31cbf86eed3b21c42 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Sat, 7 Feb 2015 00:49:41 +0530 Subject: Use the class pubsub method --- lib/action_cable/channel/redis.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/action_cable/channel/redis.rb b/lib/action_cable/channel/redis.rb index 2aca785cbe..00a8230a74 100644 --- a/lib/action_cable/channel/redis.rb +++ b/lib/action_cable/channel/redis.rb @@ -25,7 +25,7 @@ module ActionCable end def pubsub - @connection.pubsub + @connection.class.pubsub end end -- cgit v1.2.3