aboutsummaryrefslogtreecommitdiffstats
path: root/lib/action_cable/server.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2015-04-13 16:24:53 -0500
committerPratik Naik <pratiknaik@gmail.com>2015-04-13 16:24:53 -0500
commit4ac6cfefbb84a6b6ae095c20e990e5807caa9105 (patch)
tree111de3a8526b8bb9256e2f28308e65bfb04ce5a1 /lib/action_cable/server.rb
parent426fe543d7b6d6fa42ff18304770a628904f5f4c (diff)
downloadrails-4ac6cfefbb84a6b6ae095c20e990e5807caa9105.tar.gz
rails-4ac6cfefbb84a6b6ae095c20e990e5807caa9105.tar.bz2
rails-4ac6cfefbb84a6b6ae095c20e990e5807caa9105.zip
Remove all the existing connections on redis reconnect
Diffstat (limited to 'lib/action_cable/server.rb')
-rw-r--r--lib/action_cable/server.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb
index a867d8578f..bfadcee229 100644
--- a/lib/action_cable/server.rb
+++ b/lib/action_cable/server.rb
@@ -24,7 +24,18 @@ module ActionCable
end
def pubsub
- @pubsub ||= EM::Hiredis.connect(@redis_config[:url]).pubsub
+ @pubsub ||= redis.pubsub
+ end
+
+ def redis
+ @redis ||= begin
+ redis = EM::Hiredis.connect(@redis_config[:url])
+ redis.on(:reconnected) do
+ logger.info "[ActionCable] Redis reconnected. Closing all the open connections."
+ @connections.map &:close_connection
+ end
+ redis
+ end
end
def remote_connections