diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2015-02-07 00:47:45 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2015-02-07 00:47:45 +0530 |
commit | c40e52ea68e21ba5b098343c7e1f285800f97008 (patch) | |
tree | 2d3d51a8a77013406a2e9d140f15d533b7c1916d /lib | |
parent | 55c956b346dfb26a0ac5a5686f4be7f96b28cff6 (diff) | |
download | rails-c40e52ea68e21ba5b098343c7e1f285800f97008.tar.gz rails-c40e52ea68e21ba5b098343c7e1f285800f97008.tar.bz2 rails-c40e52ea68e21ba5b098343c7e1f285800f97008.zip |
Use just one redis connection
Diffstat (limited to 'lib')
-rw-r--r-- | lib/action_cable/channel/redis.rb | 11 |
1 files changed, 6 insertions, 5 deletions
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 |