Search code examples
laravellaravel-5redislaravel-queuelaravel-horizon

QUEUE_CONNECTION 'database' works but 'redis' throws 'Array to String conversion'


I am simply trying to run a Event & Listener cycle and pass a model into it

event(new LabelsCreated($model, 'string'));

This works perfectly with QUEUE_CONNECTION=database however with QUEUE_CONNECTION=redis, it throws me an error:

#message: "Array to string conversion"

#code: 0

#file: "/home/vagrant/Code/Upworks/myproj/vendor/laravel/framework/src/Illuminate/Queue/RedisQueue.php"

#line: 302

#severity: E_NOTICE

My Event class looks like this:

class LabelsCreated
{
    use Dispatchable, SerializesModels;

    public $model;

    public $string;

    public function __construct($model, $string)
    {
        $this->model = $model;
        $this->string = $string;

        // comes here
    }
}

but it doesn't queue my Listener at all.


My config/queue.php, redis array looks like this:

'redis' => [
        'driver' => 'redis',
        'connection' => 'default',
        'queue' => ['default', 'export'],
        'retry_after' => 90,
        'block_for' => null,
 ],

May it be referring to key 'queue' value?


Solution

  • This is the problem in my config/queue.php

    'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => ['default', 'export'], // THIS LINE
            'retry_after' => 90,
            'block_for' => null,
     ],
    

    I tried keeping it as default

    'queue' => 'default'
    

    and it ran multiple queues on the same connection.

    Deeper Insight: https://laracasts.com/discuss/channels/laravel/multiple-queues-for-redis-connection?page=0#reply=461404