Search code examples
node.jssocket.ioioredis

Subscribe to multiple channels with ioredis


I have a broadcast server with socket.io and ioredis via node.

However, with my current form I can only subscribe to one channel a time.

var Redis = require('ioredis');
var redis = new Redis();

redis.subscribe('mychannel');

Considering that I must have innumerable channels (one for each registered user, for instance) I cannot hard type every channel on the node server.

I've tried also redis.subscribe('*') but without success.

Any light?


Solution

  • Using redis.psubscribe('*') and redis.on('pmessage', handlerFunction) did the trick.