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!
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
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
})) ;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With