redis
redis copied to clipboard
feat: support multiple handlers for a single subscription
🔗 Linked issue
Closes #65
❓ Type of change
- [ ] 🐞 Bug fix (a non-breaking change that fixes an issue)
- [ ] 👌 Enhancement (improving an existing functionality like performance)
- [x] ✨ New feature (a non-breaking change that adds functionality)
- [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
📚 Description
Allows adding multiple handlers to a single channel subscription. The old API will still work. A new API was added for removing specific handlers without fully unsubscribing from the channel:
const handler1 = () => { /* ... */ };
// start subscription
await redis.subscribe('users/123', handler1);
const handler2 = () => { /* ... */ };
// use the existing subscription
await redis.subscribe('users/123', handler2);
// remove handler1, keep subscription alive
await redis.unsubscribe('users/123', handler1);
// no more handlers for channel, close subscription
await redis.unsubscribe('users/123', handler2);
To avoid introducing any breaking changes, the errors in errors.ts were marked @deprecated, since they are no longer relevant with the introduction of this feature.
📝 Checklist
- [x] I have linked an issue or discussion.
- [ ] I have updated the documentation accordingly.