Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with redis cluster #8

Closed
markschmid opened this issue Mar 9, 2016 · 3 comments
Closed

Usage with redis cluster #8

markschmid opened this issue Mar 9, 2016 · 3 comments

Comments

@markschmid
Copy link

We're using ioredis (https://github.com/luin/ioredis) with our redis cluster and would like to use your library as a socket.io adapter (connecting to the redis cluster).

From a quick look at the docs and the code, I did not recognize an obvious way to do so. There are options to provide existing ioredis client instances for pubClient/subClient, but not for the adapter instance itself. Any ideas highly appreciated!

@markschmid
Copy link
Author

OK, so I tried my luck by initialising the adapter with prebuilt pubClient and subClient like follows:

var redisPubClient = new ioredis.Cluster(redisNodes);
var redisSubClient = new ioredis.Cluster(redisNodes);
var ioredisSocketAdapter = require('socket.io-ioredis');
io.adapter(ioredisSocketAdapter({ host: '127.0.0.1', port: 6500, pubClient: redisPubClient, subClient: redisSubClient }));

Unfortunately, it seems it's not the correct approach:

/mydir/node_modules/socket.io-ioredis/node_modules/msgpack-js/msgpack.js:200
  if (decoder.offset !== buffer.length) throw new Error((buffer.length - decoder.offset) + " trailing bytes");
                                        ^

Error: 66 trailing bytes
    at Object.decode (/mydir/node_modules/socket.io-ioredis/node_modules/msgpack-js/msgpack.js:200:47)
    at Redis.onmessage (/mydir/node_modules/socket.io-ioredis/index.js:97:24)
    at emitTwo (events.js:87:13)
    at Cluster.emit (events.js:172:7)
    at Redis.<anonymous> (/mydir/node_modules/ioredis/lib/cluster.js:289:13)
    at emitTwo (events.js:87:13)
    at Redis.emit (events.js:172:7)
    at Redis.exports.returnReply (/mydir/node_modules/ioredis/lib/redis/parser.js:104:14)
    at HiredisReplyParser.replyParser.sendReply (/mydir/node_modules/ioredis/lib/redis/parser.js:25:10)
    at HiredisReplyParser.execute (/mydir/node_modules/ioredis/lib/parsers/hiredis.js:37:12)
    at Socket.<anonymous> (/mydir/node_modules/ioredis/lib/redis/event_handler.js:94:22)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at Socket.Readable.push (_stream_readable.js:110:10)
    at TCP.onread (net.js:523:20)

@markschmid
Copy link
Author

Engineered this some more. The msgpack error was actually my bad. Will test some more with the above setup and follow up on the results.

@markschmid
Copy link
Author

OK, for reference: it seems like this module works seamlessly with redis cluster, which is great. :)
It suffices to define pubClient and subClient opts, that's it.

var redisPubClient = new ioredis.Cluster(redisNodes);
var redisSubClient = new ioredis.Cluster(redisNodes);
var ioredisSocketAdapter = require('socket.io-ioredis');
io.adapter(ioredisSocketAdapter({ pubClient: redisPubClient, subClient: redisSubClient }));

Thanks for this library!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant