socket.io-redis-emitter icon indicating copy to clipboard operation
socket.io-redis-emitter copied to clipboard

Apply async redis features

Open vazaio opened this issue 3 years ago • 3 comments

node-redis presented new major version 4.x.x. One of the most highlighted changes is Promise support. At the current moment redis-emitter works fine with node-redis v4 :rocket:. But there can be some obstacles. For instance, if you work with AWS Lambda you have to connect to redis, do some stuff, disconnect from redis. If this.redisClient.publish() call isn't completed yet then you will receive an error.

const client = await redis.connect();
const emitter = new Emitter(client);

emitter.emit('event', data);

await client.disconnect();

// Lambda run fails

This pr fixes it. @darrachequesne please take a look at the commit. Probably it should be merged

vazaio avatar Feb 27 '22 01:02 vazaio

Hi! I think you should call quit() instead of disconnect():

Before quitting, the client executes any remaining commands in its queue, and will receive replies from Redis for each of them

From: https://github.com/redis/node-redis#quitquit

darrachequesne avatar Feb 28 '22 05:02 darrachequesne

Hi! I think you should call quit() instead of disconnect():

Before quitting, the client executes any remaining commands in its queue, and will receive replies from Redis for each of them

What if you want to keep the connection alive? As suggested from GCP Cloud Function docs, you shouldn't call quit() or disconnect() I'm not sure from your comment if you're supporting this change or not.

amitozalvo avatar Mar 24 '22 13:03 amitozalvo

@amitozalvo hi! What I meant is that I thought the use case suggested by @vazaio was already covered in the current version, but I might be wrong. Could you please explain your use case?

darrachequesne avatar Mar 24 '22 14:03 darrachequesne

Please reopen if needed.

darrachequesne avatar Jan 12 '23 05:01 darrachequesne