Yii Framework Forum: Yii2/redis and receive messages from Pub/Sub Subscription - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii2/redis and receive messages from Pub/Sub Subscription I don't get to receive messages after subscribe in Connection clas Rate Topic: -----

#1 User is offline   Raul Truco 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 19-December 17

Posted 19 December 2017 - 02:26 AM

Hello,

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

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

1) Passing as the latest parameter an array formed by [<instance>, <function name>] 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'
);


2) 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?

Thank you very much!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users