Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

subscribe fails with ConnectionError #26

Closed
milyenpabo opened this issue Aug 29, 2014 · 4 comments
Closed

subscribe fails with ConnectionError #26

milyenpabo opened this issue Aug 29, 2014 · 4 comments

Comments

@milyenpabo
Copy link

Subscribe consistently fails with ConnectionError. Example code snippet:

rc = RedisCluster(startup_nodes=[{'host': '10.0.0.1', 'port': '7001'}])
pubsub = rc.pubsub()
pubsub.subscribe(**{'mychannel': mycallback})

def mycallbak(msg):
    pass

The problem is that rc.pubsub() returns a PubSub object (from StrictRedis), which is not aware of the cluster node addresses. Thus on rc.subscribe() it tries to connect to a default Redis endpoint on localhost:6379, which fails with the following error:

redis.exceptions.ConnectionError: Error 111 connecting to localhost:6379. Connection refused.

@Grokzen
Copy link
Owner

Grokzen commented Aug 29, 2014

Thanks for the report. I will look into this during the weekend.

@Grokzen
Copy link
Owner

Grokzen commented Sep 1, 2014

@milyenpabo Added fix in the mentioned commit. Will merge it into master branch during the day so this issue will be closed.

I tested with a modified script

from rediscluster import RedisCluster


def mycallback(msg):
    print("My callback...")
    print(msg)


rc = RedisCluster(startup_nodes=[{'host': '127.0.0.1', 'port': 7001}])

pubsub = rc.pubsub()
a = pubsub.subscribe(**{'mychannel': mycallback})

for b in pubsub.listen():
    print(b)

@Grokzen Grokzen closed this as completed in f33831e Sep 1, 2014
@Grokzen
Copy link
Owner

Grokzen commented Sep 1, 2014

@milyenpabo If you have any other problems with pubsub please open more Issues with some test code and I will look into them.

@milyenpabo
Copy link
Author

Thanks for the quick fix, it works.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants