Skip to content

Commit

Permalink
chore: bump redis to version ^4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Jan 4, 2022
1 parent accf344 commit 6ba02c0
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
node-version: [12.x, 16.x]

services:
redis:
Expand Down
44 changes: 35 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,37 @@ The current version is compatible with both:

## How to use

Installation:

```
npm i @socket.io/redis-emitter redis
```

### CommonJS

Installation: `npm i @socket.io/redis-emitter redis`
```js
const { Emitter } = require("@socket.io/redis-emitter");
const { createClient } = require("redis"); // not included, needs to be explicitly installed

const redisClient = createClient();

redisClient.connect().then(() => {
const io = new Emitter(redisClient);

setInterval(() => {
io.emit("time", new Date);
}, 5000);
})
```

With `redis@3`, calling `connect()` is not needed:

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

const redisClient = createClient();

const io = new Emitter(redisClient);

setInterval(() => {
Expand All @@ -62,18 +84,19 @@ setInterval(() => {

### TypeScript

Installation: `npm i @socket.io/redis-emitter redis @types/redis`

```ts
import { Emitter } from "@socket.io/redis-emitter";
import { createClient } from "redis";

const redisClient = createClient();
const io = new Emitter(redisClient);

setInterval(() => {
io.emit("time", new Date);
}, 5000);
redisClient.connect().then(() => {
const io = new Emitter(redisClient);

setInterval(() => {
io.emit("time", new Date);
}, 5000);
});
```

With typed events:
Expand All @@ -87,9 +110,12 @@ interface Events {
}

const redisClient = createClient();
const io = new Emitter<Events>(redisClient);

io.emit("basicEmit", 1, "2", [3]);
redisClient.connect().then(() => {
const io = new Emitter<Events>(redisClient);

io.emit("basicEmit", 1, "2", [3]);
});
```

## Emit cheatsheet
Expand Down
Loading

0 comments on commit 6ba02c0

Please sign in to comment.