Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Pub/Sub On Same Client #39

Closed
daneren2005 opened this issue Aug 19, 2016 · 2 comments
Closed

Can't Pub/Sub On Same Client #39

daneren2005 opened this issue Aug 19, 2016 · 2 comments
Labels

Comments

@daneren2005
Copy link

It appears that pub sub is not really async. After trying to figure out why I wasn't receiving commands on another client, I finally tried commenting out $client->subscribe($channel); and all of a sudden the publish commands were going through.

With a client subscribe the following code never logged the publish complete message:

$this->redis->publish($this->channel, json_encode($msg))->then(function($return) {
    $this->debug('Publish received ' . $return);
});
@daneren2005 daneren2005 changed the title Sub/Pub Is Not Async Can't Pub/Sub On Same Client Aug 19, 2016
@clue clue added the question label Aug 19, 2016
@clue
Copy link
Owner

clue commented Aug 19, 2016

This is a limitation of Redis and unfortunately there's nothing this library (or any other library for that matter) can do about this. See also http://redis.io/topics/pubsub and http://redis.io/commands/subscribe.

You can easily reproduce this by connecting to your Redis instance via telnet:

$ telnet localhost 6379
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
subscribe a
*3
$9
subscribe
$1
a
:1
publish a b
-ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context

As you've already figured out, the correct workaround is to use two independent connections.

I hope this helps 👍

@clue clue closed this as completed Aug 19, 2016
@daneren2005
Copy link
Author

Oh well that stinks. I was hoping because it async it meant you could listen for replies to the subscribe and publish on the same channel. That does make sense that it is a Redis thing which you can't work around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants