node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

PUBSUB Returns Nothing

Open harryzun opened this issue 12 years ago • 2 comments

I'm trying to get the return value of the command PUBSUB NUMSUB "mychannel" by using the code:

client.pubsub(["NUMSUB", "mychannel"], function (err, res) {});

I have verified that the command is successfully parsed and sent to the Redis server, however I cannot figure out how to access the value it returns. The callback function is never called, and client.pubsub() always seems to simply return true.

Is there any way to access the return value? Since I am new to Node Redis, I can't tell if this is a bug or I'm just overlooking something.

harryzun avatar Sep 19 '14 06:09 harryzun

This seems to be working fine for me:

c.pubsub(["NUMSUB", "foo"], function (err, reply) {
  console.log("%s has %s subscribers", reply[0], reply[1])
})

// foo has 0 subscribers

You can also call it like client.pubsub("NUMSUB", "channel1", "channel2", callback)

brycebaril avatar Sep 19 '14 17:09 brycebaril

Woops, I checked back at my code this morning, and it turns out it was just a race condition issue. I had the code client.end() a few lines afterward, which would end the client before it had the chance to call the callback.

Nevertheless, thanks for your help! :)

harryzun avatar Sep 19 '14 18:09 harryzun