moaxaca / async-redis

First class async & promise support for redis.
Other
168 stars 21 forks source link

createClient method not always behaving as expected #60

Open Crono1981 opened 3 years ago

Crono1981 commented 3 years ago

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 commented 2 years ago

+1 Any news on a fix?