aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2015-04-14 13:22:34 -0500
committerPratik Naik <pratiknaik@gmail.com>2015-04-14 13:22:34 -0500
commitd6dc49456fcd5be6b034ebd2a9299bda96201972 (patch)
treea25c6144eb264f52a4af772676c575d1d27cf743
parent155db8120811b89624fb7e657818eb32ed07301a (diff)
downloadrails-d6dc49456fcd5be6b034ebd2a9299bda96201972.tar.gz
rails-d6dc49456fcd5be6b034ebd2a9299bda96201972.tar.bz2
rails-d6dc49456fcd5be6b034ebd2a9299bda96201972.zip
Revert "Revert "Remove all the existing connections on redis reconnect""
This reverts commit 155db8120811b89624fb7e657818eb32ed07301a.
-rw-r--r--lib/action_cable/connection/base.rb4
-rw-r--r--lib/action_cable/server.rb13
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/action_cable/connection/base.rb b/lib/action_cable/connection/base.rb
index e8126f3d75..93db5b3dba 100644
--- a/lib/action_cable/connection/base.rb
+++ b/lib/action_cable/connection/base.rb
@@ -100,6 +100,10 @@ module ActionCable
end
def handle_exception
+ close_connection
+ end
+
+ def close_connection
logger.error "Closing connection"
@websocket.close
diff --git a/lib/action_cable/server.rb b/lib/action_cable/server.rb
index 1780e0c028..70b0610e92 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 threaded_redis