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

add pubsub command: #80

Open
hayksaakian opened this issue Oct 30, 2014 · 1 comment
Open

add pubsub command: #80

hayksaakian opened this issue Oct 30, 2014 · 1 comment

Comments

@hayksaakian
Copy link

See:

http://redis.io/commands/pubsub

In my use case I would use it to count the number of active connections to a channel

PUBSUB NUMSUB $channels
@hagsteel
Copy link

The tornado-redis only have one subscriber to a channel and all the subscribers in your application belongs to that.

So redis would say you only have one subscriber.

If you look here:
https://github.com/leporo/tornado-redis/blob/master/tornadoredis/pubsub.py#L26

You see that as a new subscriber is added, it is actually added to a list rather than to redis.

You could count the number of subscribers in the list, however if you run multiple instances (load balancing and using multiple cores etc.) then the number would be inaccurate as you would only count the number of subscribers for that particular instance.

I did a basic online counter by doing a redis increment on a key every time someone connected, and decrement when they disconnected.

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