Skip to content

Allow for on('connect' #56

@iamjon

Description

@iamjon

Hi,
Thank you for the awesome project.
Currently your code allows for us to provide an error handler if the clients cannot connect to redis.
The code here provides this functionality.
if(channel === "error"){ self.errorHandler = handler; this.emitter.on("error", handler); this.receiver.on("error", handler); callback(); return; }

It would be amazing if we had similar code that would let us know when the handler has connected something akin to
if(channel === "connect"){ self.connectHandler = handler; this.emitter.on("connect", handler); this.receiver.on("connect", handler); callback(); return; }

Right now my code looks like this
const handler = new NRP({ url: config.redis.url }); let connected = true; function connectError(error) { if (!connectError.loggedOnce) { logger.error(error.message); connected = false; connectError.loggedOnce = true; } } // This is never called function connectSuccess() { if (!connectSuccess.loggedOnce) { logger.info('Redis Connected: ', config.redis); connectSuccess.loggedOnce = true; } } handler.on('error', connectError); handler.on('connect', connectSuccess);

Because there is no connect handler, the code has to assume the connection is good and sets the connected variable to true by default. If I was unsure of my connection and I wanted to only set the variable once connected, or if I wanted to log that a connection was made I cannot do so.

In my local env I tried adding the code above to trigger the connection handler and it worked.

Thank you,
Jonathan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions