18

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

Jonatas Walker
  • 13,583
  • 5
  • 53
  • 82
Mr punch
  • 1,756
  • 4
  • 16
  • 23

2 Answers2

8

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

Jeffrey Hill
  • 167
  • 1
  • 9
2

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
});
Jonatas Walker
  • 13,583
  • 5
  • 53
  • 82
  • what should i put in if condition in place of `name` && `constants.REDIS_SUBSCRIBER_NAME` – Mr punch Feb 12 '16 at 20:21
  • i required('redis') , then created redis_client client , then fired this script in node and it says `constants is not defined` – Mr punch Feb 13 '16 at 08:42
  • This is a name you can set to your subscriber client. `subscriber.client('setname', constants.REDIS_SUBSCRIBER_NAME);`. **Use your own name**. – Jonatas Walker Feb 13 '16 at 08:54
  • i have created a sample of what i did .. but from this sample i am not able to come to any conclusion.github sample [github sample list_subscribers_of_redis_channels](https://github.com/pawarvijay/list_subscribers_of_redis_channels) – Mr punch Feb 26 '16 at 07:53
  • also in github sample [github sample list_subscribers_of_redis_channels](https://github.com/pawarvijay/list_subscribers_of_redis_channels) i have console.log in many places and not able to make out subscribers subscribed on channel1 Or channnel2 – Mr punch Feb 26 '16 at 07:54
  • am i missing any thing in sample – Mr punch Feb 26 '16 at 07:54
  • Don't change `kv[0] == 'name'`. This is a value from Redis. – Jonatas Walker Feb 26 '16 at 10:40
  • You can also use `redis_client.client('setname', 'YOVIJAY')` instead of `CLIENT SETNAME 'YOVIJAY'` – Jonatas Walker Feb 26 '16 at 10:45