Mr punch
Mr punch

Reputation: 1906

Redis command to list all subscribers subscribed to redis channel

Below command only gives channel list .

127.0.0.1:6379> PUBSUB CHANNELS
1) "mychannel"
2) "mychanne2"

How to LIST subscribers subscribed on channel1 OR channel2 .?

also

i din't found redis command to list all subscribers Of a particular channel

Upvotes: 19

Views: 13296

Answers (2)

Jeffrey Hill
Jeffrey Hill

Reputation: 305

You can use PUBSUB NUMSUB channel1 OR PUBSUB NUMSUB channel2 and get reply about the number of subscribers for the specified channel.

Upvotes: 10

Jonatas Walker
Jonatas Walker

Reputation: 14150

I can achieve this with something like:

redis_client.multi().client(['list']).exec(function(err, results) {
  var pairs = results[0].split(' ');
  pairs.forEach(function(pair){
    var kv = pair.split('=');
    if (kv[0] == 'name' && kv[1] == constants.REDIS_SUBSCRIBER_NAME)
      found = true;
  });
  if (found) // some logic
  else // some logic
});

Upvotes: 2

Related Questions