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

createClient method not always behaving as expected #60

Open
Crono1981 opened this issue Jun 16, 2021 · 1 comment
Open

createClient method not always behaving as expected #60

Crono1981 opened this issue Jun 16, 2021 · 1 comment

Comments

@Crono1981
Copy link

Hi,

First of all, thanks for this library. It is much appreciated. Good work. :)

I ran into an issue yesterday and I managed to narrow it down to the way the createClient method works within AsyncRedis.

It seems that the method will not create two distinct client instances with the same configuration - as opposed to what the base Redis method implementation would. Instead, it keeps track of created clients and stores them in an internal array, so that a the same instance will be returned when equivalent options are a match.

I'm not sure why it was designed that way. There may be a very valid reason I'm simply unaware of. In any case, this is a problem for situations in which you do need two distinct clients on the same database, such as when one acts as a subscriber and the other as a publisher. You'd be calling createClient method twice on two distinct variables and use them as pub/sub pattern dictates; still, the code would fail at runtime with the following error message:

ERR only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context

The workaround I came up with was to create clients out of base Redis library, then use AsyncRedis.decorate on them. Works like a charm and still allows using promises.

If pooling of client instances really is the intended design for createClient, then I suggest documenting the method accordingly.

Thanks! :)

@paulcrussell
Copy link

paulcrussell commented Apr 21, 2022

+1
Any news on a fix?

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

No branches or pull requests

2 participants