Redis pub / sub subsribe returning connection error
I am on Laravel 5.1 and am following the guide here: http://laravel.com/docs/5.1/redis#pubsub
I created a simple socket.io server and on the client side I fired a message to my channel, the socket.io server was able to log the message.
However, I ran the command I did for redis pub / sub, it got nothing when the client side issued a message. After a while, an error is thrown:
[Predis \ Connection \ ConnectionException] An error occurred while reading a line from the server. [TCP: //127.0.0.1: 6379]
Then I tried using the post method in the team, it works. Socket.io server is capable of logging a 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 with
php artisan channel:sub
I am using predis / predis to support Redis in Laravel.
+3
source to share
1 answer
Laravel 5.2 change to 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
],
],
0
source to share