PHP code example of gevman / yii2-redis-subscriber

1. Go to this page and download the library: Download gevman/yii2-redis-subscriber library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gevman / yii2-redis-subscriber example snippets


'components' => [
    //...
    'redis' => [
        'class' => \yii\redis\Connection::class,
        'hostname' => 'localhost',
        'port' => 6379,
    ],
    //...
],

'components' => [
    //...
    'redisSubscriber' => [
        'class' => \Gevman\Yii2RedisSubscriber\Connection::class,
        'hostname' => 'localhost',
        'port' => 6379,
    ],
    //...
],

\Yii::$app->redis->publish('some_channel', 'some message');

\Yii::$app->redisSubscriber->listen(
    'some_channel', 
    function($type, $channel, $message) {
        do_something($type, $channel, $message);
    },
    function(\Throwable $error) {
        \Yii::error($error->getMessage());
    }
);