hapi-io icon indicating copy to clipboard operation
hapi-io copied to clipboard

Cant get it working with 'socket.io-redis'

Open arashkay opened this issue 7 years ago • 3 comments

Hi @sibartlett ,

I'm using PM2 with -i max to run my app as cluster but the initial handshake fails. There is a solution which is http://socket.io/docs/using-multiple-nodes/ by using 'socket.io-redis'

var io = require('socket.io')(3000);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));

Just tried to do something like this on server.register callback:

var io = server.plugins['hapi-io'].io;
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));

But didn't work. Any suggestion?

arashkay avatar Aug 17 '16 12:08 arashkay

I have the same problem, I use a cluster of hapi server and I need redis to redispatch to the corect server/client the events.

throrin19 avatar May 05 '17 08:05 throrin19

Anyone able to get this working?

barakyo avatar Jan 29 '18 23:01 barakyo

You need to add the adapter to the plugin config, something like the this:

import HapiIO from 'hapi-io';
import ioRedis from 'socket.io-redis';
...
{
  register: HapiIO,
  options: {
    socketio: {
      adapter: ioRedis({
        host: process.env.REDIS_HOST,
        port: process.env.REDIS_PORT,
      }),
    },
  },
},
...

drphelps avatar Jun 03 '18 00:06 drphelps