Redis Driver

This driver uses Redis to store queue data.

You have to add the yiisoft/yii2-redis extension to your application in order to use it.

Configuration example:

return [
    'bootstrap' => [
        'queue', // The component registers its own console commands
    ],
    'components' => [
        'redis' => [
            'class' => \yii\redis\Connection::class,
            // ...

            // retry connecting after connection has timed out
            // yiisoft/yii2-redis >=2.0.7 is required for this.
            'retries' => 1,
        ],
        'queue' => [
            'class' => \yii\queue\redis\Queue::class,
            'redis' => 'redis', // Redis connection component or its config
            'channel' => 'queue', // Queue channel key
        ],
    ],
];

Console

Console commands are used to execute and manage queued jobs.

yii queue/listen [timeout]

The listen command launches a daemon which infinitely queries the queue. If there are new tasks they're immediately obtained and executed. The timeout parameter specifies the number of seconds to sleep between querying the queue. This method is most efficient when the command is properly daemonized via supervisor or systemd.

yii queue/run

The run command obtains and executes tasks in a loop until the queue is empty. This works well with cron.

The run and listen commands have options:

  • --verbose, -v: print execution statuses to console.
  • --isolate: verbose mode of a job execution. If enabled, the execution results of each job will be printed.
  • --color: enable highlighting for verbose mode.
yii queue/info

The info command prints out information about the queue status.

yii queue/clear

The clear command clears the queue.

yii queue/remove [id]

The remove command removes a job from the queue.