PHP code example of dweik / laravel-redis-stream

1. Go to this page and download the library: Download dweik/laravel-redis-stream 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/ */

    

dweik / laravel-redis-stream example snippets


$app->register(LaravelStream\Redis\StreamServiceProvider::class);

$app->register(Illuminate\Redis\RedisServiceProvider::class);

    'channels' => [
        'channel-name' => [
            App\Channels\SomeClassChannel::class
        ],
    ],

    'trim' => [
        'channel-name' => 1000, // it means keep 1000 messages at most
    ],
 
use LaravelStream\Redis\Facades\Stream;

class SomeClass {

    public function(){
    
        /*
        .
        . some code
        .        
        */
        
        
        /**
        *
        * @var string  $channel   channel name
        * @var mixed   $data      the message data
        * @var integer $trim      (default null) the channel messages size,
        *                         when using (null) value, this package will use 
        *                         the defined value on the config file "config/streaming.php".
        *                         when using (zero) value that means stop trimming function
        */
        
        $messageID = Stream::stream( $channel, $data, $trim);
        
        
    
    }

}

bash
    php artisan make:channel-listener SomeClassChannel
bash
    php artisan stream:run