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

No way to quit a BLOCKed connection? #2746

Closed
PaulHamdinger opened this issue May 1, 2024 · 2 comments
Closed

No way to quit a BLOCKed connection? #2746

PaulHamdinger opened this issue May 1, 2024 · 2 comments

Comments

@PaulHamdinger
Copy link

Am I right in understanding that there is no way to disconnect a client while that client is blocking? I have a script where I keep an XREAD open indefinitely with BLOCK 0, but when it's time to exit my script I can't call quit() (it never completes) or disconnect() ("DisconnectsClientError").

...
redis_client.sendCommand( [ `XREAD`, `BLOCK`, `0`, `STREAMS`, `foo:bar`, `$` ] );
await redis_client.quit(); // Queue'd forever? Never run.
await redis_client.disconnect(); // Error : DisconnectsClientError: Disconnects client at Commander.disconnect...
...
@leibale
Copy link
Collaborator

leibale commented May 2, 2024

Redis (the server) processes commands in order, so QUIT will wait for XREAD BLOCK to finish before processing the QUIT command.
Regarding disconnect - that should work, but it'll make the sendCommand promise throw DisconnectsClientError which you'll need to catch.

client.sendCommand([`XREAD`, `BLOCK`, `0`, `STREAMS`, `foo:bar`, `$` ])
  .then(result => {
    // this will be called if/when the command is process successfully
  })
  .catch(err => {
    // this will be called if/when the command did not process successfully for any reason, including calling `disconnect` before the command is finished
  });

await client.disconnect(); // will cause any running commands to throw/be rejected with `DisconnectsClientError`

@PaulHamdinger
Copy link
Author

Thanks for the help, that works.

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