php - Laravel 5.1 working with redis -


here routes.php

route::get('hello1',function(){     redis::publish('test-channel', json_encode(['foo' => 'bar'])); }); 

here app.js

var app = require('express')(); var http = require('http').server(app); var io = require('socket.io')(http); var redis = require('ioredis'); var redis = new redis();   app.get('/', function(req, res){     res.sendfile(__dirname + '/index.html'); });   redis.subscribe('test-channel', function () {     console.log('redis: test-channel subscribed'); });  redis.on('message', function(channel, message) {     console.log('redis: message on ' + channel + ' received!');     console.log(message);     message = json.parse(message);     io.emit(channel, message.payload) });  io.on('connection', function(socket){     console.log('a user connected');     socket.on('disconnect', function(){         console.log('user disconnected');     }); });   http.listen(6379, function(){     console.log('listening on *:6379'); }); 

my index.html

<!doctype html> <html> <head>     <title>socket.io</title> </head> <body> <ul id="messages">     <li>hardcoded message</li> </ul>  <script src="/socket.io/socket.io.js"></script> <script src="http://code.jquery.com/jquery-1.11.1.js"></script> <script>     var socket = io();     socket.on("test-channel", function(message) {         console.log(message);         $('#messages').append($('<li>').text(message));     }); </script> </body> </html> 

now whenever run php artisan redis:subscribe or hello1 route getting error like,

connectionexception in abstractconnection.php line 146: error while reading line server. [tcp://localhost:6379]

redis default listening on port 6379 , have set http server listen on same port. won't work, don't error when trying run node app? if don't error, redis not running @ or listening on port.

if redis instance listening on port, laravel try connect redis on port 6379 , hit on node server , therefor, can't connect redis there no redis node http server listening on port.

if redis instance listening on port , have changed in laravel config, have change way connecting ioredis redis passing port:

for example

var redis = new redis(6380)  

see github page further details on connecting ioredis redis.

as conclusion, make sure that

  1. redis running
  2. your http server listening on port redis is
  3. your connection settings redis in config/database.php , config/broadcast.php (laravel) , node in server.js file correct

note not http server connecting redis, ioredis is.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -