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

How to receive messages from Pub/Sub Subscription #131

Open
raultruco opened this issue Dec 19, 2017 · 3 comments
Open

How to receive messages from Pub/Sub Subscription #131

raultruco opened this issue Dec 19, 2017 · 3 comments
Labels
type:enhancement Enhancement

Comments

@raultruco
Copy link

raultruco commented Dec 19, 2017

Hello, I'm not sure if this feature is implemented in Yii2-redis extension....
but I wanted to work with Pub/Sub using this extension, specifically receive messages of a subscribed key in Redis. Publish part is working fine instead.

I have tried several ways to receive the messages from other publishers:

  1. Passing as the latest parameter an array formed by [, ] or a string with the function name. This is how native PHP redis driver works. But I get an error saying: 'mb_strlen() expects parameter 1 to be string, object given'
$subscriptionResponse = Yii::$app->redisSubscriber->subscribe(
    'sync',
    [$this, '_handleSyncInMessage']
);

or

$subscriptionResponse = Yii::$app->redisSubscriber->subscribe(
    'sync',
    '_handleSyncInMessage'
);
  1. Putting the callback function inline doesn't work neither. The same error: 'mb_strlen() expects parameter 1 to be string, object given'
$subscriptionResponse = Yii::$app->redisSubscriber->subscribe(
    'sync',
    function($redis, $channel, $message) {
      echo 'Never arrived here..."
    }
);

The following code doesn't throw any error, but I don't know how to receive the messages when other processes publish in the key 'sync':

Yii::$app->redisSubscriber->subscribe('sync');

Anyone has a working example of this?

I also put this question in yiiframework forums here

Thank you!

@cebe
Copy link
Member

cebe commented Dec 30, 2017

The redis connection is currently developed to work with commands that do return values and end then. the subscribe command will receive data and never stop until it unsubscribes, so this is currently not supported.

@cebe cebe added the type:enhancement Enhancement label Dec 30, 2017
@cebe cebe added this to the 2.0.x milestone Dec 30, 2017
@samdark samdark removed this from the 2.0.x milestone Apr 16, 2019
@razonyang
Copy link
Contributor

@samdark Is this feature planed in 3.0?

@samdark
Copy link
Member

samdark commented Apr 24, 2019

We haven't thought about Redis yet.

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

No branches or pull requests

4 participants