gevman/yii2-redis-subscriber

Yii2 Redis Channel Subscriber implementation for yii2-redis

1.3.0 2021-07-14 12:08 UTC

This package is auto-updated.

Last update: 2024-12-14 19:22:57 UTC


README

Yii2 Redis Channel Subscriber implementation for yii2-redis

installation

using composer

composer require gevman/yii2-redis-subscriber
  • Configuration (pusher project)
'components' => [
    //...
    'redis' => [
        'class' => \yii\redis\Connection::class,
        'hostname' => 'localhost',
        'port' => 6379,
    ],
    //...
],
  • Configuration (subscriber project)
'components' => [
    //...
    'redisSubscriber' => [
        'class' => \Gevman\Yii2RedisSubscriber\Connection::class,
        'hostname' => 'localhost',
        'port' => 6379,
    ],
    //...
],

Usage

  • Push message to channel
\Yii::$app->redis->publish('some_channel', 'some message');
  • Listen channel messages
\Yii::$app->redisSubscriber->listen(
    'some_channel', 
    function($type, $channel, $message) {
        do_something($type, $channel, $message);
    },
    function(\Throwable $error) {
        \Yii::error($error->getMessage());
    }
);