Skip to content

Commit 73ce3ea

Browse files
[feature] Make subEvent default to messageBuffer (#157)
With that subscription event the `return_buffers` flag is not needed anymore.
1 parent aae6f21 commit 73ce3ea

3 files changed

Lines changed: 9 additions & 24 deletions

File tree

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The following options are allowed:
3232
- `key`: the name of the key to pub/sub events on as prefix (`socket.io`)
3333
- `host`: host to connect to redis on (`localhost`)
3434
- `port`: port to connect to redis on (`6379`)
35-
- `subEvent`: optional, the redis client event name to subscribe to (`message`)
35+
- `subEvent`: optional, the redis client event name to subscribe to (`messageBuffer`)
3636
- `pubClient`: optional, the redis client to publish events on
3737
- `subClient`: optional, the redis client to subscribe to events on
3838
- `requestsTimeout`: optional, after this timeout the adapter will stop waiting from responses to request (`1000ms`)
@@ -42,12 +42,6 @@ If you decide to supply `pubClient` and `subClient`, make sure you use
4242
[node_redis](https://github.com/mranney/node_redis) as a client or one
4343
with an equivalent API.
4444

45-
If you supply clients, make sure you initialized them with
46-
the `return_buffers` option set to `true`.
47-
48-
You can supply [ioredis](https://github.com/luin/ioredis) as a client
49-
by providing `messageBuffer` as the subEvent option.
50-
5145
### RedisAdapter
5246

5347
The redis adapter instances expose the following properties
@@ -89,12 +83,10 @@ a connection string.
8983
var redis = require('redis').createClient;
9084
var adapter = require('socket.io-redis');
9185
var pub = redis(port, host, { auth_pass: "pwd" });
92-
var sub = redis(port, host, { return_buffers: true, auth_pass: "pwd" });
86+
var sub = redis(port, host, { auth_pass: "pwd" });
9387
io.adapter(adapter({ pubClient: pub, subClient: sub }));
9488
```
9589

96-
Make sure the `return_buffers` option is set to `true` for the sub client.
97-
9890
## Protocol
9991

10092
The `socket.io-redis` adapter broadcasts and receives messages on particularly named Redis channels. For global broadcasts the channel name is:

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ function adapter(uri, opts){
4747
var sub = opts.subClient;
4848

4949
var prefix = opts.key || 'socket.io';
50-
var subEvent = opts.subEvent || 'message';
50+
var subEvent = opts.subEvent || 'messageBuffer';
5151
var requestsTimeout = opts.requestsTimeout || 1000;
5252
var withChannelMultiplexing = false !== opts.withChannelMultiplexing;
5353

5454
// init clients if needed
55-
function createClient(redis_opts) {
55+
function createClient() {
5656
if (uri) {
5757
// handle uri string
58-
return redis(uri, redis_opts);
58+
return redis(uri, opts);
5959
} else {
60-
return redis(opts.port, opts.host, redis_opts);
60+
return redis(opts);
6161
}
6262
}
6363

6464
if (!pub) pub = createClient();
65-
if (!sub) sub = createClient({ return_buffers: true });
65+
if (!sub) sub = createClient();
6666

6767
// this server's key
6868
var uid = uid2(6);

test/index.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ var adapter = require('../');
1212
var redis = require('redis').createClient;
1313
var srv = http();
1414
var sio = io(srv);
15-
sio.adapter(adapter({
16-
pubClient: redis(),
17-
subClient: redis(null, null, { return_buffers: true })
18-
}));
15+
sio.adapter(adapter());
1916
srv.listen(function(err){
2017
if (err) throw err; // abort tests
2118
if ('function' == typeof nsp) {
@@ -32,12 +29,9 @@ var adapter = require('../');
3229
{
3330
name: 'socket.io-redis without channel multiplexing',
3431
create: function create(nsp, fn){
35-
var redis = require('redis').createClient;
3632
var srv = http();
3733
var sio = io(srv);
3834
sio.adapter(adapter({
39-
pubClient: redis(),
40-
subClient: redis(null, null, { return_buffers: true }),
4135
withChannelMultiplexing: false
4236
}));
4337
srv.listen(function(err){
@@ -61,8 +55,7 @@ var adapter = require('../');
6155
var sio = io(srv);
6256
sio.adapter(adapter({
6357
pubClient: redis(),
64-
subClient: redis(null, null, { return_buffers: true }),
65-
subEvent: 'messageBuffer'
58+
subClient: redis(),
6659
}));
6760
srv.listen(function(err){
6861
if (err) throw err; // abort tests

0 commit comments

Comments
 (0)