3

I am on Laravel 5.1 and following the guide here: http://laravel.com/docs/5.1/redis#pubsub

I created a simple socket.io server and on client side i emitted a message to my-channel, socket.io server is able to log the message.

However, I ran the command i made for redis pub/sub, it does not recieved anything when client side has emitted a message. After a while, an error is thrown:

[Predis\Connection\ConnectionException] Error while reading line from the server. [tcp://127.0.0.1:6379]

Then i tried to use publish method in the command, it works. socket.io server is able to log the message.

Here's my console command

<?php

namespace App\Console\Commands;

use Illuminate\Support\Facades\Redis;
use Illuminate\Console\Command;

class ChannelSub extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'channel:sub';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        Redis::subscribe(['my-channel'], function($message) {
            $this->info($message);
        });
    }
}

Try it with

php artisan channel:sub

I am using predis/predis for Redis support in Laravel.

Laurence
  • 58,936
  • 21
  • 171
  • 212
ElsT
  • 139
  • 4
  • 15
  • Please take a look at this topic's answer and see if it helps :) http://stackoverflow.com/questions/11776029/predis-is-giving-error-while-reading-line-from-server – Harry Geo Jun 18 '15 at 11:06
  • i seen that, how do i set the ?read_write_timeout=0 to my subscribe method? thanks – ElsT Jun 18 '15 at 11:17
  • I guess you should set this parameter where you set up the connection. Propably somewhere inside vendor/'predis_package_path'/config . Not sure haven't actually used redis. But I know the functionality it provides. I also understand you are trying to send messages through websockets – Harry Geo Jun 18 '15 at 11:23

1 Answers1

1

Laravel 5.2 change on config/database.php

'redis' => [

    'cluster' => false,

    'default' => [
        'host' => env('REDIS_HOST', 'localhost'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => 0,
    ],
    'subscribe' => [
        'host' => env('REDIS_HOST', 'localhost'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        'database' => 0,
        'read_write_timeout' => 0
    ],

],