~/redis $ node socket.js
events.js:160
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at Server._listen2 (net.js:1257:14)
at listen (net.js:1293:10)
at Server.listen (net.js:1389:5)
at Object.<anonymous> (/Users/abdureshid/redis/socket.js:15:6)
atModule._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
atModule.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
atFunction.Module._load (module.js:438:3)
atModule.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3
出现了以上报错, socket代码如下:
var http = require('http').Server();
var io = require('socket.io')(http);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test-channel');
redis.on('message', function (channel, message) {
console.log(channel + ':' + message);
});
http.listen(3000);
route 文件测试代码如下:
useIlluminate\Support\Facades\Redis;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
Route::get('/', function(){
$data = [
'aNewMessage',
'data'=>[
'name'=>'test-name'
]
];
Redis::publish('test-channel',json_encode($data));
});
[ioredis] Unhandled error event: Error: connect ETIMEDOUT
at Socket. (/Users/Jone/sites/redis/node_modules/ioredis/lib/redis.js:289:21)
at Object.onceWrapper (events.js:314:30)
at emitNone (events.js:105:13)
at Socket.emit (events.js:207:7)
at Socket._onTimeout (net.js:402:8)
at ontimeout (timers.js:488:11)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:283:5)