PHP code example of elmys / yii2-queue-redis

1. Go to this page and download the library: Download elmys/yii2-queue-redis 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/ */

    

elmys / yii2-queue-redis example snippets


const QUEUE_ACCOUNT = 'queueAccount'; // Here will be real names of your queue on redis created
const QUEUE_BILLING = 'queueBilling';
const QUEUE_OTHER = 'queueOther';

const LAYER_DEV = '0';
const LAYER_STAGE = '1';
const LAYER_PROD = '9';

const LAYERS = [
    LAYER_DEV => 'dev',
    LAYER_STAGE => 'stage',
    LAYER_PROD => 'prod',
];

const ONE_QUEUES = [
    QUEUE_ACCOUNT,
    QUEUE_BILLING,
];
const TWO_QUEUES = [
    QUEUE_OTHER,
];
const ALL_QUEUES = [
    'one-micro-service' => ONE_QUEUES, // these array keys for CSS-styling only
    'two-micro-service' =>  TWO_QUEUES,    
];

$redis = ootstrap = _DIR__ . '/queues-local.php';


return [
    'class' => \yii\redis\Connection::class,
    'retries' => 1,
    'hostname' => 'your_hostname',
    'port' => 6379,
    'database' => 0,
    'password' => 'your_password',
];


return array_merge(ONE_QUEUES, TWO_QUEUES);


use yii\queue\redis\Queue;
$redisComponent = 'redis';
$queues = 'class' => Queue::class,
        'redis' => $redisComponent,
        'channel' => $queue,
    ];
}

return $res;

$config = [
    ...
    'bootstrap' => array_merge(['log'], $queuesBootstrap),
    'components' => [
            'queues' => $queues,
            ...
            'i18n' => [
                        'translations' => [
                            'queueRedis*' => [
                                'class' => 'yii\i18n\PhpMessageSource',
                                'basePath' => '@vendor/elmys/yii2-queue-redis/messages',
                            ],
                        ],
                    ],
    ...

public function init()
    {
        elmys\yii2\queueRedis\actions\QueueRedisAction::staticInit();
        parent::init();
    }

$layerName = LAYERS[elmys\yii2\queueRedis\actions\QueueRedisAction::$appLayer] ?? null;

public function actions()
    {
        return array_merge(parent::actions(), [
            'index' => [
                'class' => 'elmys\yii2\queueRedis\actions\QueueRedisAction',
            ],
            'queue-clear' => [
                'class' => 'elmys\yii2\queueRedis\actions\QueueRedisCleanAction',
            ],
            ...
            'error' => [
                'class' => 'yii\web\ErrorAction',
            ],
        ]);
    }

php composer.phar 
require __DIR__ . '/../config/definitions.php';