Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating socket.io from 0.9.x to 1.x, Problems with configuring RedisStore

So I am migrating my node application from socket.io 0.9.x to 1.x, and I am having issues with configuring the RedisStore. I had this working when using 0.9.x, but I can't figure out how to get it working with 1.x. The documentation appears to only work for 0.9.x. Here's the relevant portion from their documentation, which I followed and had working with the old version:

var RedisStore = require('socket.io/lib/stores/redis')
  , redis  = require('socket.io/node_modules/redis')
  , pub    = redis.createClient()
  , sub    = redis.createClient()
  , client = redis.createClient();

io.set('store', new RedisStore({
  redisPub : pub
, redisSub : sub
, redisClient : client
}));

From what I can tell the problem appears to be this part:

var RedisStore = require('socket.io/lib/stores/redis')
  , redis  = require('socket.io/node_modules/redis')

Those files do not appear to exist anymore within the socket.io module.

Also, I've been using their migration guide as a reference, but it has no mention of specific changes to how to configure the RedisStore.

Any help or ideas would be greatly appreciated. Thanks!

like image 861
c.hill Avatar asked May 30 '14 10:05

c.hill


2 Answers

In case anyone else has the same troubles that I did, here's how I got it working again..

First you'll need to install the socket.io-redis module:

npm install socket.io-redis --save

Then, from within your node app, you'll need to replace your previous socket+redis-related configuration code with the following:

var redis = require('socket.io-redis')

io.adapter(redis({
    host: 'localhost',
    port: 6379
}))

That's it!

Reference links:

https://github.com/automattic/socket.io-redis

like image 77
c.hill Avatar answered Nov 16 '22 03:11

c.hill


For socket.io > 0.9 this is done through io.adapter using socket.io-redis Check the link https://github.com/Automattic/socket.io-redis

var redis = require('socket.io-redis') ;
io.adapter(redis({
    host: 'localhost',
    port: 6379
})) ;
like image 39
Arpit Joshi Avatar answered Nov 16 '22 01:11

Arpit Joshi