Skip to content

Commit 8fe4e03

Browse files
committedMay 4, 2018
[docs] Fix Cluster example in the README
The previous example would lead to "Connection in subscriber mode, only subscriber commands may be used" errors. Fixes #274
1 parent e9cbe30 commit 8fe4e03

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed
 

‎README.md

+12-8
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,10 @@ io.adapter(redisAdapter({ pubClient: pub, subClient: sub }));
196196

197197
```js
198198
const io = require('socket.io')(3000);
199+
const redisAdapter = require('socket.io-redis');
199200
const Redis = require('ioredis');
200201

201-
const cluster = new Redis.Cluster([
202+
const startupNodes = [
202203
{
203204
port: 6380,
204205
host: '127.0.0.1'
@@ -207,16 +208,19 @@ const cluster = new Redis.Cluster([
207208
port: 6381,
208209
host: '127.0.0.1'
209210
}
210-
]);
211+
];
211212

212-
const redisAdapter = require('socket.io-redis');
213-
io.adapter(redisAdapter({ pubClient: cluster, subClient: cluster }));
213+
io.adapter(redisAdapter({
214+
pubClient: new Redis.Cluster(startupNodes),
215+
subClient: new Redis.Cluster(startupNodes)
216+
}));
214217
```
215218

216219
### Sentinel Example
217220

218221
```js
219222
const io = require('socket.io')(3000);
223+
const redisAdapter = require('socket.io-redis');
220224
const Redis = require('ioredis');
221225

222226
const options = {
@@ -227,10 +231,10 @@ const options = {
227231
name: 'master01'
228232
};
229233

230-
const pubClient = new Redis(options);
231-
const subClient = new Redis(options);
232-
233-
io.adapter(redisAdapter({ pubClient: pubClient, subClient: subClient }));
234+
io.adapter(redisAdapter({
235+
pubClient: new Redis(options),
236+
subClient: new Redis(options)
237+
}));
234238
```
235239

236240
## Protocol

0 commit comments

Comments
 (0)
Please sign in to comment.