How to determine number of clients listening for broadcasting?

575 views Asked by At

I am using laravel 5.1 and I want to know how many clients are listening to a particular channel say Test-Channel. I want this number on server? Is there any way I can get it? Further I am using Broadcasting with Redis.

The link to broadcasting document is as follows:

Laravel 5.1 Event Broadcasting

1

There are 1 answers

2
Linus Thiel On

There is command for this in redis. Check out PUBSUB NUMSUB:

Returns the number of subscribers (not counting clients subscribed to patterns) for the specified channels.

And PUBSUB NUMPAT:

Returns the number of subscriptions to patterns (that are performed using the PSUBSCRIBE command). Note that this is not just the count of clients subscribed to patterns but the total number of patterns all the clients are subscribed to.

Edit: It's also worth noting that the PUBLISH command also returns number of receivers:

Return value

Integer reply: the number of clients that received the message.