@@ -48,58 +48,58 @@ const io = new Server();
48
48
const pubClient = createClient ({ host: ' localhost' , port: 6379 });
49
49
const subClient = pubClient .duplicate ();
50
50
51
- io .adapter (createAdapter (pubClient, subClient));
52
-
53
- // redis@3
54
- io .listen (3000 );
55
-
56
- // redis@4
57
51
Promise .all ([pubClient .connect (), subClient .connect ()]).then (() => {
52
+ io .adapter (createAdapter (pubClient, subClient));
58
53
io .listen (3000 );
59
54
});
60
55
```
61
56
62
- ### ES6 modules
57
+ With ` redis@3 ` , calling ` connect() ` on the Redis clients is not needed:
63
58
64
59
``` 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' ) ;
68
63
69
64
const io = new Server ();
70
65
const pubClient = createClient ({ host: ' localhost' , port: 6379 });
71
66
const subClient = pubClient .duplicate ();
72
67
73
68
io .adapter (createAdapter (pubClient, subClient));
74
69
75
- // redis@3
76
70
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 ();
77
83
78
- // redis@4
79
84
Promise .all ([pubClient .connect (), subClient .connect ()]).then (() => {
85
+ io .adapter (createAdapter (pubClient, subClient));
80
86
io .listen (3000 );
81
87
});
82
88
```
83
89
84
90
### TypeScript
85
91
86
92
``` ts
87
- // npm i -D redis @types/redis
88
93
import { Server } from ' socket.io' ;
94
+ import { createClient } from ' redis' ;
89
95
import { createAdapter } from ' @socket.io/redis-adapter' ;
90
- import { RedisClient } from ' redis' ;
91
96
92
97
const io = new Server ();
93
98
const pubClient = createClient ({ host: ' localhost' , port: 6379 });
94
99
const subClient = pubClient .duplicate ();
95
100
96
- io .adapter (createAdapter (pubClient , subClient ));
97
-
98
- // redis@3
99
- io .listen (3000 );
100
-
101
- // redis@4
102
101
Promise .all ([pubClient .connect (), subClient .connect ()]).then (() => {
102
+ io .adapter (createAdapter (pubClient , subClient ));
103
103
io .listen (3000 );
104
104
});
105
105
```
0 commit comments