From 4ac6cfefbb84a6b6ae095c20e990e5807caa9105 Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 13 Apr 2015 16:24:53 -0500 Subject: Remove all the existing connections on redis reconnect --- lib/action_cable/server.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/action_cable/server.rb') 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 -- cgit v1.2.3