Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis command to get all available channels for pub/sub?

I search through redis command list. I couldn't find the command to get all the available channels in redis pub/sub. In meteor server, the equivalent command is LISTCHANNELS, where it lists all known channels, the number of messages stored on each one and the number of current subscribers.

I have a cron that needs to periodically know about the available channels. Does redis have native command for this? Or I need to find a way to implement it myself?

like image 250
Shuwn Yuan Tee Avatar asked Nov 17 '11 09:11

Shuwn Yuan Tee


People also ask

Does Redis support pub sub?

Aside from data storage, Redis can be used as a Publisher/Subscriber platform. In this pattern, publishers can issue messages to any number of subscribers on a channel. These messages are fire-and-forget, in that if a message is published and no subscribers exists, the message evaporates and cannot be recovered.

How do I use Redis as a pub sub?

Redis Pub/Sub implements the messaging system where the senders (in redis terminology called publishers) sends the messages while the receivers (subscribers) receive them. The link by which the messages are transferred is called channel. In Redis, a client can subscribe any number of channels.

How can I see my Redis subscribers?

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

How do I get all Redis keys?

To list the keys in the Redis data store, use the KEYS command followed by a specific pattern. Redis will search the keys for all the keys matching the specified pattern. In our example, we can use an asterisk (*) to match all the keys in the data store to get all the keys.


2 Answers

PUBSUB CHANNELS does this as of version 2.8.0.

like image 133
nahelm Avatar answered Sep 22 '22 11:09

nahelm


There is no existing command - look at http://redis.io/commands#pubsub. You can save all channels' names in SET and retrieve them, when it is required.

like image 42
Ilia Kondrashov Avatar answered Sep 21 '22 11:09

Ilia Kondrashov