1
votes

I'm writing a p2p communication between two or more node process with redis pub/sub
using ioredis lib.

I will publish different types of messages like:

  • hello: to let know to others subscriber that a new process is connected
  • wanna-pick: to let a process to ask to others process if it can take a "work"
  • pick: as acknowledge to notify the other process

I don't know if it is better for redis v3.2.1 to subscribe to many channels (one per message type) or create a single channel and send a json-message with an attribute that defines the message's type like:

{type: 'hello', message: 'hello i'm process foo' }

{type: 'wanna-pick', message: 'foo wanna pick work 42' }

Thanks in advance

1

1 Answers

1
votes

Both solutions are good. I don't think there's any performance difference between these two solutions. If you really have too many channels, that might cost Redis some more memory. However, that should NOT be a problem. Do some benchmarks, if you DO care about it.

Personally, I prefer the second solution, i.e. a single channel. With a single channel, when you add or remove a type, clients don't need to subscribe to a new channel or unsubscribe from the removed channel. Although that should NOT be a big deal.