Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis should not be a dependency #89

Closed
MickL opened this issue Dec 31, 2020 · 6 comments
Closed

Redis should not be a dependency #89

MickL opened this issue Dec 31, 2020 · 6 comments
Milestone

Comments

@MickL
Copy link

MickL commented Dec 31, 2020

May you add an example how to use with TypeScript? I tried both:

const io = require('socket.io-emitter')({ host: '127.0.0.1', port: 6379 });

and

import * as socketIoEmitter from 'socket.io-emitter';
const io = socketIoEmitter({ host: '127.0.0.1', port: 6379 });

but i get:

ERROR in ./node_modules/socket.io-emitter/node_modules/redis-parser/lib/hiredis.js 3:14-32
Module not found: Error: Can't resolve 'hiredis' in '/Users/mick/git/myproject/node_modules/socket.io-emitter/node_modules/redis-parser/lib'

Btw. should redis be a peerDependency? I already have Redis in my project (v3) and socket.io-emitter imports v2 so I have two instances running.

@darrachequesne
Copy link
Member

Hi! I could not reproduce the issue, both examples seem to work.

That's a bit weird though:

But hiredis is not in the dependencies of the redis-parser package...

should redis be a peerDependency?

I think it should even be in the devDependencies list, and let the user provide its own redis client.

const io = require('socket.io-emitter')(redisClient, { /* additional options */});

But this change would need to be well documented..

I already have Redis in my project (v3) and socket.io-emitter imports v2 so I have two instances running.

You should be able to create the emitter instance with a redis client v3 (the example above).

@MickL
Copy link
Author

MickL commented Jan 3, 2021

The problem are the dependencies: I already have redis v3 in my project and this package imports redis v2. If I change redis for this package to v3 then it works.

I think redis should at least be a peerDependency

@MickL MickL changed the title Add TypeScript documentation Redis should not be a dependency Jan 4, 2021
@MickL
Copy link
Author

MickL commented Jan 4, 2021

Hey @darrachequesne I see you updated the readme. Can we still remove redis from the dependencies and force the user to insert a client?

@darrachequesne
Copy link
Member

Yes, let's do this 👍

darrachequesne added a commit that referenced this issue Mar 17, 2021
The codebase is now written in TypeScript.

Additional features:

- https://socket.io/docs/v4/migrating-from-3-x-to-4-0/#Allow-excluding-specific-rooms-when-broadcasting
- https://socket.io/docs/v4/migrating-from-3-x-to-4-0/#Additional-utility-methods
- https://socket.io/docs/v4/migrating-from-3-x-to-4-0/#Typed-events

BREAKING CHANGE: the "redis" package is not installed by default
anymore, you'll now need to create your own redis client and pass it to
the Emitter constructor

Before:

```js
const io = require("socket.io-emitter")({ host: "127.0.0.1", port: 6379 });
```

After:

```js
const { Emitter } = require("socket.io-emitter");
const { createClient } = require("redis");

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

Related:

- #89
- #90
- #95
@darrachequesne
Copy link
Member

Done in a70db12.

You'll now need to explicitly install the redis package (or another compatible package like ioredis), and pass it in the Emitter constructor:

const { Emitter } = require("socket.io-emitter");
const { createClient } = require("redis");

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

@darrachequesne darrachequesne added this to the 4.0.0 milestone Mar 17, 2021
@MickL
Copy link
Author

MickL commented Mar 18, 2021

Thats nice! I did the same at nats-emitter https://github.com/MickL/socket.io-nats-emitter#readme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants