Skip to content

Conversation

@JH8459
Copy link
Contributor

@JH8459 JH8459 commented Nov 4, 2025

Summary

I'm using this library in a production project β€” it has been very helpful, thanks for maintaining it! πŸ™
While reviewing the internal implementation, I found the clear() method a bit hard to follow because it mixed Promise construction and event callbacks.

This PR refactors clear() to use a modern async iterator pattern (for await...of) with batched pipeline deletion,
making the flow easier to read and maintain without changing the behavior.


Changes

  • Simplified clear() by replacing manual Promise and stream.on(...) callbacks with for await...of.
  • Each SCAN batch is deleted through pipeline.del() followed by pipeline.exec().
  • No changes to the method signature or functionality.

Why

The previous version worked fine but relied on nested callbacks and explicit Promise construction,
which made it less straightforward to read.
Using async iteration improves readability and aligns with modern Node.js async I/O practices.


Notes

  • Tested with Redis v7.2 and Node 22.
  • No breaking changes.
  • This PR focuses purely on internal readability and maintainability improvements.

Thanks again for the great library!

@ramiel ramiel merged commit d53eae0 into ramiel:main Nov 4, 2025
0 of 4 checks passed
@ramiel
Copy link
Owner

ramiel commented Nov 4, 2025

Thanks. Yes, definitely more readable. Some log messages are now missing but I can put them back later

@ramiel
Copy link
Owner

ramiel commented Nov 4, 2025

Available in new version 4.0.1

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

Successfully merging this pull request may close these issues.

2 participants