Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why pub sub in redis cannot be used together with other commands?

Tags:

redis

I'm reading here, and I see a warning stating that PUB/SUB subscribers in Redis should not issue other commands:

A client subscribed to one or more channels should not issue commands, although it can subscribe and unsubscribe to and from other channels.

I have two questions:

  • Why is this limitation?
  • For the scope of the paragraph, what's a client? A whole process? A Redis connection? A complete Redis instance? Or is it a bad idea in general to issue commands and subscribe to channels, and the admonition goes for every and any scope I can think of?
like image 809
dsign Avatar asked Nov 29 '15 12:11

dsign


1 Answers

A client, in this case, is an instance of a connection to Redis. An application could well have multiple clients, each with different responsibilities or as a way to provide higher degrees of parallelism to the application.

What they are suggesting here, however, is that you use an individual client (think 'connection') to handle your incoming subscription messages and to react to those messages as its sole responsibility. The reason it's recommended not to make calls with this connection is because while it is waiting on incoming messages from subscribed channels, the client is in a blocked state.

Trying to make a call on a given client won't work while it's awaiting response from a blocking call.

like image 196
Darren Hicks Avatar answered Oct 23 '22 01:10

Darren Hicks