Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Ensure that there are no subscribers if there is no Redis connection #73

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tornadoredis/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def subscribe(self, channel_name, subscriber, callback=None):
subscriber - a method or object to be used by on_message handler
callback - a callback function
"""

# If for some reason the redis client is not connected (the server might have gone down)
# then clear the subscribers. This ensure that there are no subscribers since there possibly can't be an
# active Redis subscription
if not self.redis.connection.connected():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won't solve the issue.
I think we need to add a "reconnect" event handler, sending "subscribe/psubscribe" messages for each handled channel.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are absolutely right, this was more of a quick fix (before I applied this to my fork it stopped responding after the server had been running for a while, but with this it doesn't).

I would be more than happy to throw some ideas around.

self.subscribers = defaultdict(Counter)
self.subscriber_count = Counter()

if isinstance(channel_name, list) or isinstance(channel_name, tuple):
if len(channel_name) > 1:
_cb = lambda *args, **kwargs: self.subscribe(channel_name[1:],
Expand Down