ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

lazyConnect bug

Open ghost opened this issue 4 years ago • 2 comments

There is a bug right now, if u set lazyConnect = true, still Redis can connect itself without you calling .connect(), just use any redis commands.

I guess if lazyConnect is true then any inner attempt to connect should be disabled and Error can be thrown.

Originally posted by @Kamil93 in https://github.com/luin/ioredis/issues/6#issuecomment-889349451

ghost avatar Jul 29 '21 18:07 ghost

Hey @Kamil93, actually it's expected. In lazy mode, the connection won't be made unless the connect method is called explicitly or any Redis methods are about to sent. It is designed to work transparently and is useful when ex in cluster mode you need to connect to hundreds nodes whereas only very small amounts of nodes will be actually used to send commands to.

luin avatar Jul 30 '21 04:07 luin

But still it's unintuitive in simple usage.

I think then, the best option would be fixing connect method, to not throw an error when called more than ones. Instead, connect should always return promise that always resolves. When client is in connecting state then it waits among other/previous connect() calls, when connected just resolve promise immediatelly.

What do You think?

ghost avatar Jul 30 '21 07:07 ghost