1

下面是我如何初始化和发出,但我没有发现任何错误,我的服务器也没有监听,接收任何事件。

const io = require('socket.io-emitter')({
  host: 127.0.0.1,
  // path: do i need this ?
  port: redisUri.port,
  pub: pub, // is the key required to be the same as the app ?
  sub: sub, // is the key required to be the same as the app ?
});

io.emit('test', 'test'})

我尝试了很多变化,有人可以启发我如何调试这个吗?

我也尝试在对象之前添加一个 redis href。

4

1 回答 1

0

我发现了错误,问题出在 pub 和 sub 套接字上。

这是解决方案:

var pub = redisPassword ? redis.createClient(6379, localhost, {return_buffers: true, auth_pass: redisPassword}) : undefined;
var sub = redisPassword ? redis.createClient(6379, localhost, {detect_buffers: true, return_buffers: true, auth_pass: redisPassword}) : undefined;
socketio.adapter(require('socket.io-redis')({ host: localhost, port: 6379, pubClient: pub, subClient: sub }));

这就是问题所在:

我没有将其设置为 undefined 来检查密码,而是创建了另一个客户端,将其设置为默认值更容易。

请让我知道我是否可以改进我的代码。谢谢你。

于 2018-01-09T01:19:25.223 回答