PHP code example of riorizkyrainey / pubsub-redis-php

1. Go to this page and download the library: Download riorizkyrainey/pubsub-redis-php 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/ */

    

riorizkyrainey / pubsub-redis-php example snippets


composer 

$client = new Predis\Client([
    'scheme' => 'tcp',
    'host' => 'redis',
    'port' => 6379,
    'database' => 0,
    'read_write_timeout' => 0,
]);

$redisSubscribeAdapter = new \RioRizkyRainey\PubsubRedis\RedisSubscribeAdapter();
$redisSubscribeAdapter->setClient($client)
    ->setChannel('channel')
    ->subscribe(function ($message) {
        printf($message . PHP_EOL);
    });


$client = new Predis\Client([
    'scheme' => 'tcp',
    'host' => 'redis',
    'port' => 6379,
    'database' => 0,
    'read_write_timeout' => 0,
]);

$redisPublishAdapter = new \RioRizkyRainey\PubsubRedis\RedisPublishAdapter();
$redisPublishAdapter->setClient($client)
    ->setChannel('channel');

$redisPublishAdapter->publishMessage('Hi, How do you do?');
$redisPublishAdapter->publishBulkMessage(['Nice to meet you', 'Where are you going?']);
$redisPublishAdapter->publishMessage('I don\'t feel good mr stark');