node-redis icon indicating copy to clipboard operation
node-redis copied to clipboard

quit vs disconnect - flipped behaviour or wrong documentation

Open 7c opened this issue 1 year ago • 3 comments
trafficstars

Description

based on the docs at https://redis.js.org/#node-redis-usage-disconnecting the disconnect should close the connection without flushing and quit close with flushing before closing. Current implementation is not in sync with this approach as seen here https://github.com/redis/node-redis/blob/dbf8f59a47573e6a1c75b78e566af8c493015d5d/packages/client/lib/client/index.ts#L847

for me it looks like reversed, quit seems not try to flush commands but disconnect does.

image

this screenshot demonstrates disconnect behaviour if redis has a ping in the queue, it does try to flush and because ping does not handle .catch it calls 'Unhandled rejection'. We indeed need the .quit() or .disconnect() which should ignore the queue and just close the connection without 'Unhandled rejection' because imagine if you are using third-party-libraries you neven know how people have managed the redis commands..

is this wrong documentation or flipped implementation ?

Node.js Version

20.11.1

Redis Server Version

Node Redis Version

4.6.13

Platform

macOS

Logs

No response

7c avatar Mar 14 '24 11:03 7c

Correction: .quit also seems to wait with Promise.all to quit from the redisconnection (https://github.com/redis/node-redis/blob/dbf8f59a47573e6a1c75b78e566af8c493015d5d/packages/client/lib/client/index.ts#L722). So at the end i see no method which should break a connection gracefully.I also could not find a method to clear the redis queue to call before disconect.

7c avatar Mar 14 '24 11:03 7c