Redis command to list all subscribers subscribed to redis channel
Asked Answered
O

2

19

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

Olag answered 11/2, 2016 at 17:14 Comment(0)
S
10

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

Sentence answered 30/3, 2018 at 3:35 Comment(0)
N
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
});
Nga answered 11/2, 2016 at 20:23 Comment(8)
what should i put in if condition in place of name && constants.REDIS_SUBSCRIBER_NAMEOlag
i required('redis') , then created redis_client client , then fired this script in node and it says constants is not definedOlag
This is a name you can set to your subscriber client. subscriber.client('setname', constants.REDIS_SUBSCRIBER_NAME);. Use your own name.Nga
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_channelsOlag
also in github sample github sample list_subscribers_of_redis_channels i have console.log in many places and not able to make out subscribers subscribed on channel1 Or channnel2Olag
am i missing any thing in sampleOlag
Don't change kv[0] == 'name'. This is a value from Redis.Nga
You can also use redis_client.client('setname', 'YOVIJAY') instead of CLIENT SETNAME 'YOVIJAY'Nga

© 2022 - 2024 — McMap. All rights reserved.