Skip to content

Commit

Permalink
Merge pull request socketio#95 from omrilitov/master
Browse files Browse the repository at this point in the history
Add support to ioredis
  • Loading branch information
rauchg committed Apr 3, 2016
2 parents f758337 + 40fd543 commit e8e8b01
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ results

npm-debug.log
node_modules
.idea
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ The following options are allowed:
- `key`: the name of the key to pub/sub events on as prefix (`socket.io`)
- `host`: host to connect to redis on (`localhost`)
- `port`: port to connect to redis on (`6379`)
- `subEvent`: optional, the redis client event name to subscribe to (`message`)
- `pubClient`: optional, the redis client to publish events on
- `subClient`: optional, the redis client to subscribe to events on

Expand All @@ -42,6 +43,9 @@ with an equivalent API.
If you supply clients, make sure you initialized them with
the `return_buffers` option set to `true`.

You can supply [ioredis](https://github.com/luin/ioredis) as a client
by providing `messageBuffer` as the subEvent option.

### RedisAdapter

The redis adapter instances expose the following properties
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function adapter(uri, opts){
var pub = opts.pubClient;
var sub = opts.subClient;
var prefix = opts.key || 'socket.io';
var subEvent = opts.subEvent || 'message';

// init clients if needed
if (!pub) pub = redis(port, host);
Expand Down Expand Up @@ -74,7 +75,7 @@ function adapter(uri, opts){
sub.subscribe(prefix + '#' + nsp.name + '#', function(err){
if (err) self.emit('error', err);
});
sub.on('message', this.onmessage.bind(this));
sub.on(subEvent, this.onmessage.bind(this));
}

/**
Expand Down

0 comments on commit e8e8b01

Please sign in to comment.