i am unclear of how to use socket.io-emitter (serv

2019-07-27 12:11发布

Below is how i initialize and emit but i dont find any errors nor do my server listening, receives any events.

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'})

i tried many variations, can someone enlighten me how can i debug this ?

ive tried to add a redis href before the object as well.

1条回答
SAY GOODBYE
2楼-- · 2019-07-27 12:57

I found the error,

the issue was with the pub and sub sockets

here's the solution :

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 }));

this was the issue :

instead of having it at undefined for the checking of password, I created another client, it was easier to set it to default. Please do let me know if I could improve my code. Thank you.

查看更多
登录 后发表回答