Skip to content

Commit 6ba02c0

Browse files
chore: bump redis to version ^4.0.1
See also: https://github.com/redis/node-redis/blob/master/docs/v3-to-v4.md
1 parent accf344 commit 6ba02c0

File tree

5 files changed

+193
-96
lines changed

5 files changed

+193
-96
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [10.x, 12.x, 14.x]
15+
node-version: [12.x, 16.x]
1616

1717
services:
1818
redis:

Readme.md

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,37 @@ The current version is compatible with both:
4444

4545
## How to use
4646

47+
Installation:
48+
49+
```
50+
npm i @socket.io/redis-emitter redis
51+
```
52+
4753
### CommonJS
4854

49-
Installation: `npm i @socket.io/redis-emitter redis`
55+
```js
56+
const { Emitter } = require("@socket.io/redis-emitter");
57+
const { createClient } = require("redis"); // not included, needs to be explicitly installed
58+
59+
const redisClient = createClient();
60+
61+
redisClient.connect().then(() => {
62+
const io = new Emitter(redisClient);
63+
64+
setInterval(() => {
65+
io.emit("time", new Date);
66+
}, 5000);
67+
})
68+
```
69+
70+
With `redis@3`, calling `connect()` is not needed:
5071

5172
```js
5273
const { Emitter } = require("@socket.io/redis-emitter");
5374
const { createClient } = require("redis"); // not included, needs to be explicitly installed
5475

5576
const redisClient = createClient();
77+
5678
const io = new Emitter(redisClient);
5779

5880
setInterval(() => {
@@ -62,18 +84,19 @@ setInterval(() => {
6284

6385
### TypeScript
6486

65-
Installation: `npm i @socket.io/redis-emitter redis @types/redis`
66-
6787
```ts
6888
import { Emitter } from "@socket.io/redis-emitter";
6989
import { createClient } from "redis";
7090

7191
const redisClient = createClient();
72-
const io = new Emitter(redisClient);
7392

74-
setInterval(() => {
75-
io.emit("time", new Date);
76-
}, 5000);
93+
redisClient.connect().then(() => {
94+
const io = new Emitter(redisClient);
95+
96+
setInterval(() => {
97+
io.emit("time", new Date);
98+
}, 5000);
99+
});
77100
```
78101

79102
With typed events:
@@ -87,9 +110,12 @@ interface Events {
87110
}
88111

89112
const redisClient = createClient();
90-
const io = new Emitter<Events>(redisClient);
91113

92-
io.emit("basicEmit", 1, "2", [3]);
114+
redisClient.connect().then(() => {
115+
const io = new Emitter<Events>(redisClient);
116+
117+
io.emit("basicEmit", 1, "2", [3]);
118+
});
93119
```
94120

95121
## Emit cheatsheet

0 commit comments

Comments
 (0)