Skip to content

Commit d55d6e5

Browse files
docs: fix example with redis v4
It seems the clients must be connected before creating the adapter. Related: #436
1 parent 1687394 commit d55d6e5

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -48,58 +48,58 @@ const io = new Server();
4848
const pubClient = createClient({ host: 'localhost', port: 6379 });
4949
const subClient = pubClient.duplicate();
5050

51-
io.adapter(createAdapter(pubClient, subClient));
52-
53-
// redis@3
54-
io.listen(3000);
55-
56-
// redis@4
5751
Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
52+
io.adapter(createAdapter(pubClient, subClient));
5853
io.listen(3000);
5954
});
6055
```
6156

62-
### ES6 modules
57+
With `redis@3`, calling `connect()` on the Redis clients is not needed:
6358

6459
```js
65-
import { Server } from 'socket.io';
66-
import { createClient } from 'redis';
67-
import { createAdapter } from '@socket.io/redis-adapter';
60+
const { Server } = require('socket.io');
61+
const { createClient } = require('redis');
62+
const { createAdapter } = require('@socket.io/redis-adapter');
6863

6964
const io = new Server();
7065
const pubClient = createClient({ host: 'localhost', port: 6379 });
7166
const subClient = pubClient.duplicate();
7267

7368
io.adapter(createAdapter(pubClient, subClient));
7469

75-
// redis@3
7670
io.listen(3000);
71+
```
72+
73+
### ES6 modules
74+
75+
```js
76+
import { Server } from 'socket.io';
77+
import { createClient } from 'redis';
78+
import { createAdapter } from '@socket.io/redis-adapter';
79+
80+
const io = new Server();
81+
const pubClient = createClient({ host: 'localhost', port: 6379 });
82+
const subClient = pubClient.duplicate();
7783

78-
// redis@4
7984
Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
85+
io.adapter(createAdapter(pubClient, subClient));
8086
io.listen(3000);
8187
});
8288
```
8389

8490
### TypeScript
8591

8692
```ts
87-
// npm i -D redis @types/redis
8893
import { Server } from 'socket.io';
94+
import { createClient } from 'redis';
8995
import { createAdapter } from '@socket.io/redis-adapter';
90-
import { RedisClient } from 'redis';
9196

9297
const io = new Server();
9398
const pubClient = createClient({ host: 'localhost', port: 6379 });
9499
const subClient = pubClient.duplicate();
95100

96-
io.adapter(createAdapter(pubClient, subClient));
97-
98-
// redis@3
99-
io.listen(3000);
100-
101-
// redis@4
102101
Promise.all([pubClient.connect(), subClient.connect()]).then(() => {
102+
io.adapter(createAdapter(pubClient, subClient));
103103
io.listen(3000);
104104
});
105105
```

0 commit comments

Comments
 (0)